Casie Bao


All the lights we cannot see


All about Pytorch

Tensor

grad_fn

Each variable has a .grad_fn attribute that references a function that has created a function (except for Tensors created by the user, these have None as .grad_fn).

For example, we create x=torch.ones(2,2, requires_grad=True), then x.grad_fn = None, since we create the tensor x ourselves. And for y=x+2, then y is tensor([[3,3]], grad_fn=<AddBackward0>).

When run y_pred = model(X_test_tensor), get the following error RuntimeError: Expected object of scalar type Float but got scalar type Double for xxxxx. Solve by y_pred = model(X_test_tensor.float()).

Debug CUDA

  • In command line, use CUDA_LAUNCH_BLOCKING=1 python <script>.py

Watch GPU usage

  • watch -n 0.5 nvidia-smi

Multi-gpu, results is a list

item 0 in the list, is results assigned to gpu 0 1, 1. etc

Latest Articles

Leetcode

Table of Contents System Design Stack Queue Priority Queue Implementation: Heap Graph-based DSA DFS Toplogical Sort Binary Search ...…

Read More
Eariler Articles

Python argparse and namespace

What is argparse?The Python argparse module defines what arguments it requires, and argparse will figure out how to parse those out of sys.argv. It also automatically generates help and usage messa...…

Read More