ROKO

Pytorch function summary 본문

Develop

Pytorch function summary

RO_KO 2023. 1. 10. 20:25
728x90

This page is pytorch function summary got used to in paper.

Docs will be updated forever.

 

TORCH.TOPK

torch.topk(input, k, dim=None, largest=True, sorted=True, *, out=None)

 

- Returns the k largest elements of the given input tensor along a given dimension.

 

Parameters:

  • 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

 

torch.scatter(input, dim, index, src) → Tensor

- Out-of-place version of torch.Tensor.scatter_()

 

TORCH.TENSOR.ITEM

Tensor.item() → number

- contverts Tensor(one element) to plain python number

- Use when you need python number during training(GPU), take value to CPU

- Python number can live only in CPU

 

TORCH.TENSOR.TOLIST

Tensor.tolist() → list or number

- convert number or list to plain python number

- higjer version of TORCH.TENSOR.ITEM

 

TORCH.MM

torch.mm(input, mat2, *, out=None) -> Tensor

- Performs a matrix multiplication of the matrices input and mat2.

 

TORCH.ADDMM

torch.addmm(input, mat1, mat2, *, beta=1, alpha=1, out=None) → Tensor

- \(out = \beta input + \alpha(mat1_i@mat2_i)\)

- If mat1 is a \((n \times m)\) tensor, mat2 is a \((m \times p)\) tensor, then input must be broadcastable with a \((n \times p)\)tensor and out will be a \((n \times p)\) tensor

 

TORCH.TENSOR.DIM

Tensor.dim() → int 

- Returns the number of dimensions of self tensor

 

TORCH.EQUAL

torch.equal(input, other) → bool

- If two tensor have same size and elements ,then return true, else false

 

TORCH.CHUNK

torch.chunk(input, chunks, dim=0) → List of Tensors

- split input tensor to the number of chunks(int)

- e.g. torch.chunk([1,2,3,4],2,dim=0) = [[1,2],[3,4]] 

 

TORCH.NN.PARMETER.PARAMETER

torch.nn.parameter.Parameter(data=None, requires_grad=True)

- subclass of tensor

- parameters : data(Tensor), requres_grad(Bool)

 

TORCH.NN.MODULE.REGISTER_PARAMETER

register_parameter(name, param)

- adds parameter to module

parameters:

  • name(str)
  • param(Parameter or None) if None cuda ignore this parameters, is not contained operations

 

 

 

 

728x90

'Develop' 카테고리의 다른 글

How to read NVIDIA spec?  (2) 2023.01.11
How to use tqdm?  (0) 2023.01.11
zsh: command not found: conda  (0) 2023.01.05
AttributeError: module 'scipy.sparse' has no attribute 'coo_array'  (0) 2023.01.04
Comments