13 Matching Annotations
  1. Jul 2023
    1. Code for processing data samples can get messy and hard to maintain; we ideally want our dataset code to be decoupled from our model training code for better readability and modularity.

      Code for data processing and model training should be separated as different modules.

    1. Tensors on the CPU and NumPy arrays can share their underlying memory locations, and changing one will change the other.

      PyTorch tensors and NumPy arrays share memory locations. This means that changes in one reflect in both.

  2. Mar 2023
    1. For example, if you are using TensorFlow, you might save your model as a .h5 file using the Keras API. If you are using PyTorch, you might save your model as a .pt file using the torch.save() function. By saving your model as a file, you can easily load it into a deployment environment (such as FastAPI) and use it to make predictions on new images
  3. Aug 2021
    1. def compare_state_dict(dict1, dict2): # compare keys for key in dict1: if key not in dict2: return False for key in dict2: if key not in dict1: return False for (k,v) in dict1.items(): if not torch.all(torch.isclose(v, dict2[k])) return False return True

      Comparing two pytorch dicts

  4. Mar 2021
    1. PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { m.def("forward", &lltm_forward, "LLTM forward"); m.def("backward", &lltm_backward, "LLTM backward"); }

      For functions, you can simply attach the function using .def directly.

  5. Oct 2020
    1. 可能在返回Tensor底层数据中使用了新的内存


      如果直接调用 t3=t.contiguous().view(-1)

      t3 和 t 共享同一块内存,即没有使用新的内存。

    2. 需要先使用 t2 的 stride (1, 4) 转换到 t2 的结构,再基于 t2 的结构使用 stride (1,) 转换为形状为 (12,)的 b 。但这不是view工作的方式,view 仅在底层数组上使用指定的形状进行变形,即使 view 不报错,它返回的数据是

      作者的意思大概是:.view() 操作需要 stride 和 size 相匹配。

      但是 .transpose() 只修改了 stride,这导致 stride 和 size 不匹配 (compatible) 所以无法进行 .view() 操作。

    3. Tensor底层一维数组元素的存储顺序与Tensor按行优先一维展开的元素顺序是否一致。


    4. torch.view等方法操作需要连续的Tensor

      torch.view 为什么需要连续的 (contiguous) 的 Tensor

  6. Aug 2019
  7. Jul 2019
  8. Feb 2019
    1. Each tensor has a .grad_fn attribute that references a Function that has created the Tensor (except for Tensors created by the user - their grad_fn is None).

      问:tensor的.grad_fn属性表示什么意思? 答:每个tensor都有一个.grad_fn属性,该属性引用已创建Tensor的Function(除了用户创建的Tensors - 他们的grad_fn为None)。

  9. Jan 2018