torch

Losing all training gains when switching to another PC

Losing all training gains when switching to another PC Question: I am losing all of my training gains when moving to another PC and I can’t figure out why, it should be saving the model after each chunk and it does so because when I restart it on the same PC, the loss is the …

Total answers: 1

Torch in python unable to get some layers like add from model structure

Torch in python unable to get some layers like add from model structure Question: I have this simple code to write down structure of network. model = torch.jit.load(‘best5.torchscript’) file_object = open(‘sample.txt’, ‘a’) for name, module in model.named_modules(): file_object.write(str(module)) Problem is that some layers like "add" is not present for example this is part from output …

Total answers: 1

Get all layers including operators from torch in python

Get all layers including operators from torch in python Question: I want to get all layers like convolution etc… and operator like "add" in python but I really dont know how. This is my code import torch # An instance of your model. model = torch.jit.load(‘best5.torchscript’) # Print all the layers for name, param in …

Total answers: 1

Torchserve custom handler – how to pass a list of tensors for batch inferencing

Torchserve custom handler – how to pass a list of tensors for batch inferencing Question: I am trying to create a custom handler in torchserve and want to also use torchserve’s batch capability for parallelism for optimum use of resources. I am not able to find out how to write custom handler for this inference. …

Total answers: 1

How can I normalize after masking?

How can I normalize after masking? Question: Suppose I have a tensor like [0.6, 0.7, 0.4] and a mask like: [1, 0,0] How can I normalize it to: [1,0,0] my try: normalized_attn_scores = F.softmax(attn_scores, 1) normalized_attn_scores = normalized_attn_scores.mul(attn_mask) But it doesn’t produce the desired output Asked By: Ahmad || Source Answers: You can normalize after …

Total answers: 1

encoded_sentence = [label2int[start_index] for generated_text in input_sentence] keyerror:2

encoded_sentence = [label2int[start_index] for generated_text in input_sentence] keyerror:2 Question: This is a SentenceRecoghizedModel,it can’t work,I don’t have much experience on this,can somebody help me? import torch import torch.nn as nn import torch.optim as optim #導入訓練模型 text = "" #將text中的字數轉換成數字 chars = list(set(text)) #建立labels,用以儲存不同的句子 labels = [""] int2label = dict(enumerate(labels)) label2int = {label: index for index, …

Total answers: 1

Is there a difference between torch.IntTensor and torch.Tensor

Is there a difference between torch.IntTensor and torch.Tensor Question: When using PyTorch tensors, is there a point to initialize my data like so: X_tensor: torch.IntTensor = torch.IntTensor(X) Y_tensor: torch.IntTensor = torch.IntTensor(Y) Or should I just do the ‘standard’: X_tensor: torch.Tensor = torch.Tensor(X) Y_tensor: torch.Tensor = torch.Tensor(Y) even though I know X: list[list[int] and Y: list[list[int] …

Total answers: 2

Understanding fancy einsum equation

Understanding fancy einsum equation Question: I was reading about attention and came across this equation: import einops from fancy_einsum import einsum import torch x = torch.rand((200, 10, 768)) y = torch.rand((20, 768, 64)) res = einsum("batch query_pos d_model, n_heads d_model d_head -> batch query_pos n_heads d_head", x, y) And I am not able to understand …

Total answers: 1

module 'torch.onnx.symbolic_helper' has no attribute 'quantized_args'

module 'torch.onnx.symbolic_helper' has no attribute 'quantized_args' Question: while importing transforms from torchvision I am getting the following error module ‘torch.onnx.symbolic_helper’ has no attribute ‘quantized_args’ import that I performed from torchvision import transforms prior to the error it throws following warnings: OnnxExporterWarning: Symbolic function ‘aten::_shape_as_tensor’ already registered for opset 9. Replacing the existing function with new …

Total answers: 1

Runtime Error: mat1 and mat2 shapes cannot be multiplied (16×756900 and 3048516×30)

Runtime Error: mat1 and mat2 shapes cannot be multiplied (16×756900 and 3048516×30) Question: How can I solve this problem? class Net(nn.Module): def __init__(self): super().__init__() self.conv1 = nn.Conv2d(3,8,11, padding=0) # in_channel, out_channel, kernel size self.pool = nn.MaxPool2d(2,2) # kernel_size, stride self.conv2 = nn.Conv2d(8, 36, 5, padding=0) self.fc1 = nn.Linear(36*291*291, 30) # in_features, out_features self.fc2 = nn.Linear(30, …

Total answers: 1