id stringlengths 7 11 | source stringclasses 1
value | category stringclasses 11
values | title stringlengths 15 214 | text stringlengths 70 30.5k | url stringlengths 57 160 | tags stringlengths 3 113 | created_at int64 1.22B 1.79B |
|---|---|---|---|---|---|---|---|
se_79607611 | stackoverflow | MACHINE_LEARNING | More efficient way to compute elementwise gradients (Jacobian) in PyTorch while preserving create_graph | More efficient way to compute elementwise gradients (Jacobian) in PyTorch while preserving create_graph
I’m currently using PyTorch’s torch.autograd.functional.jacobian to compute per-sample, elementwise gradients of a scalar-valued model output w.r.t. its inputs. I need to keep create_graph=True because I want the re... | https://stackoverflow.com/questions/79607611/more-efficient-way-to-compute-elementwise-gradients-jacobian-in-pytorch-while | python, pytorch, gradient, autograd | 1,746,478,242 |
se_79607736 | stackoverflow | MACHINE_LEARNING | How does pytorch indexing work with lists of lists vs lists of lists of lists vs tensors | How does pytorch indexing work with lists of lists vs lists of lists of lists vs tensors
Following examples show how you can get two different answers depending on whether you have list of lists, or lists of list of lists, or 2d pytorch tensor. What is the logic used to go from the indexing array to one of the two out... | https://stackoverflow.com/questions/79607736/how-does-pytorch-indexing-work-with-lists-of-lists-vs-lists-of-lists-of-lists-vs | python, pytorch | 1,746,485,600 |
se_79410822 | stackoverflow | MACHINE_LEARNING | How does PyTorch autograd backpropogate successfully through non-tensor elements in the computational graph for the example REINFORCE code? | How does PyTorch autograd backpropogate successfully through non-tensor elements in the computational graph for the example REINFORCE code?
I am trying to understand the example REINFORCE PyTorch implementation on PyTorch GitHub: https://github.com/pytorch/examples/blob/main/reinforcement_learning/reinforce.py
One par... | https://stackoverflow.com/questions/79410822/how-does-pytorch-autograd-backpropogate-successfully-through-non-tensor-elements | pytorch, backpropagation, autograd, policy-gradient-descent | 1,738,652,842 |
se_78165875 | stackoverflow | MACHINE_LEARNING | How to broadcast a tensor from main process using Accelerate? | How to broadcast a tensor from main process using Accelerate?
I want to do some computation in the main process and broadcast the tensor to other processes. Here is a sketch of what my code looks like currently:
from accelerate.utils import broadcast
x = None
if accelerator.is_local_main_process:
x = <do_some_com... | https://stackoverflow.com/questions/78165875/how-to-broadcast-a-tensor-from-main-process-using-accelerate | python, pytorch, huggingface, accelerate | 1,710,495,029 |
se_68095962 | stackoverflow | MACHINE_LEARNING | PyTorch error when running PyTorch image on Kubernetes | PyTorch error when running PyTorch image on Kubernetes
I have a Docker image that uses PyTorch to perform object detection.
The container runs fine on local and on Google Colab, however when running on Kubernetes (through Airflow) it raises the following error:
[2021-06-23 07:13:17,592] {pod_launcher.py:148} INFO - Tr... | https://stackoverflow.com/questions/68095962/pytorch-error-when-running-pytorch-image-on-kubernetes | python, pytorch, airflow, torchvision | 1,624,435,615 |
se_79606201 | stackoverflow | MACHINE_LEARNING | How to update a leaf variable in PyTorch | How to update a leaf variable in PyTorch
I am trying to implement simple gradient descent to find the root of a quadratic equation using PyTorch. I'm doing this to get a better sense of how the autograd function works but it's not going very well. Let's say that I want to find the roots of
y = 3x^2 + 4x + 9
as a rando... | https://stackoverflow.com/questions/79606201/how-to-update-a-leaf-variable-in-pytorch | python, pytorch | 1,746,405,590 |
se_79603672 | stackoverflow | MACHINE_LEARNING | python 3.13 - ChatTTS transformer text to speech | python 3.13 - ChatTTS transformer text to speech
I'm trying to use ChatTTS which uses Torch. I installed it via the Pycharm packages repository (PIP) with no errors.
But when I run the main webpages basic example code.
import ChatTTS
import torch
import torchaudio
chat = ChatTTS.Chat()
chat.load(compile=False) # Set ... | https://stackoverflow.com/questions/79603672/python-3-13-chattts-transformer-text-to-speech | python-3.x, pytorch, torch | 1,746,199,962 |
se_74832665 | stackoverflow | MACHINE_LEARNING | Transfer Learning for Vanilla Neural Network | Transfer Learning for Vanilla Neural Network
Is it possible to do transfer learning for vanilla neural network?
I meant vanilla neural network as classic classification prediction such as whether the transaction is a fraud, the employee may quit the job, etc.
I have a trained neural network model which I would like to... | https://stackoverflow.com/questions/74832665/transfer-learning-for-vanilla-neural-network | tensorflow, machine-learning, pytorch, neural-network | 1,671,264,828 |
se_70871980 | stackoverflow | MACHINE_LEARNING | Is there an annotation tool for instance segmentation on Ipad? | Is there an annotation tool for instance segmentation on Ipad?
Is there an annotation tool to produce multi layer (for overlapping objects within the image) and pixel exact image annotations on IPad?
Background to my question:
There a lot of annotation tools for Linux and Windows
(e.g. the ones listed here: https://ww... | https://stackoverflow.com/questions/70871980/is-there-an-annotation-tool-for-instance-segmentation-on-ipad | ipad, deep-learning, pytorch, image-annotations | 1,643,244,001 |
se_79600870 | stackoverflow | MACHINE_LEARNING | torch round to two significant digits? | torch round to two significant digits?
I have jupyter notebook mess that I am attempting to refactor into proper unit tests. I would like to copy-paste some output from actual data into my test cases. However, my data are long gnarly fractional numbers. For conciseness, I would prefer to have less verbose values. ... | https://stackoverflow.com/questions/79600870/torch-round-to-two-significant-digits | pytorch | 1,746,036,026 |
se_79590865 | stackoverflow | MACHINE_LEARNING | log_prob for custom uniform distribution in PyTorch | log_prob for custom uniform distribution in PyTorch
When computing the dist.log_prob function for a uniform distribution on a box dist, the results seems to be -inf for the coordinates that are out-of-bound and -log(upper - lower) for the coordinates that are within the corresponding boundaries of the box. For instanc... | https://stackoverflow.com/questions/79590865/log-prob-for-custom-uniform-distribution-in-pytorch | pytorch, probability | 1,745,505,064 |
se_79495211 | stackoverflow | MACHINE_LEARNING | OSError when importing PyTorch: "Error loading torch_python.dll or one of its dependencies" | OSError when importing PyTorch: "Error loading torch_python.dll or one of its dependencies"
I installed PyTorch using pip install torch, but when I try to import it, I get the following error:
OSError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import to... | https://stackoverflow.com/questions/79495211/oserror-when-importing-pytorch-error-loading-torch-python-dll-or-one-of-its-de | machine-learning, deep-learning, pytorch | 1,741,478,612 |
se_79600102 | stackoverflow | MACHINE_LEARNING | Creating Venv fails due to ModuleNotFoundError: No module named 'torch' | Creating Venv fails due to ModuleNotFoundError: No module named 'torch'
I have cloned this Github repo into VSCode in order to start a new project. While trying to create a virtual environment with venv, VSCode detected the requirements.txt and asked me for permission to install all dependencies mentioned ther... | https://stackoverflow.com/questions/79600102/creating-venv-fails-due-to-modulenotfounderror-no-module-named-torch | python, visual-studio-code, pytorch, pip, python-venv | 1,746,008,219 |
se_79589904 | stackoverflow | MACHINE_LEARNING | Validation raises CUDA Out Of Memory Error despite training being fine | Validation raises CUDA Out Of Memory Error despite training being fine
I am trying to train a model for spell check errors and corrections using T5-small model in colab notebook using T4 GPU. Initially I started with 10k reviews but gradually reduced it to 2k since I was receiving CUDA out of memory error. Now with 2k... | https://stackoverflow.com/questions/79589904/validation-raises-cuda-out-of-memory-error-despite-training-being-fine | python, pytorch, huggingface-transformers, training-data | 1,745,474,091 |
se_79597887 | stackoverflow | MACHINE_LEARNING | PyTorch with Docker issues: torch.cuda.is_available() = False | PyTorch with Docker issues: torch.cuda.is_available() = False
I'm having an issue with PyTorch in a Docker container where torch.cuda.is_available() returns False, but the same PyTorch version works correctly outside the container.
Environment
Host: Debian 12
GPU: NVIDIA GeForce RTX 3060 Ti (Driver Version: 550.54.14... | https://stackoverflow.com/questions/79597887/pytorch-with-docker-issues-torch-cuda-is-available-false | python, docker, pytorch, bert-language-model, nvidia-docker | 1,745,913,811 |
se_79598235 | stackoverflow | MACHINE_LEARNING | subprocess.CalledProcessError: Command '['ninja']' returned non-zero exit status 1 | subprocess.CalledProcessError: Command '['ninja']' returned non-zero exit status 1
how to resolve this error
[SPARSE] Backend: spconv, Attention: flash_attn
/usr/local/lib/python3.11/dist-packages/gradio_client/utils.py:1097: UserWarning: file() is deprecated and will be removed in a future version. Us... | https://stackoverflow.com/questions/79598235/subprocess-calledprocesserror-command-ninja-returned-non-zero-exit-status | python, pytorch | 1,745,925,361 |
se_73136920 | stackoverflow | MACHINE_LEARNING | Logging in Custom Handler for TorchServe | Logging in Custom Handler for TorchServe
I have written a custom handler for an DL model using torch-serve and am trying to understand how to add manual log messages to the handler. I know that I can simply print any messages and it will show them within the MODEL_LOG logger at level INFO.
What if I want to add a cust... | https://stackoverflow.com/questions/73136920/logging-in-custom-handler-for-torchserve | python, pytorch, torchserve | 1,658,920,449 |
se_72854762 | stackoverflow | MACHINE_LEARNING | How to turn tensor type to original text (before tokenized) in Pytorch | How to turn tensor type to original text (before tokenized) in Pytorch
for example, a tensor type data below is tokenized by a kind of English tokenizer.
tensor([[ 2992, 1852, 9439, ..., 2610, 1704, 29189],
[ 1852, 9439, 7, ..., 1704, 29189, 23223],
[ 9439, 7, 2367, ..., 29189, 23223,... | https://stackoverflow.com/questions/72854762/how-to-turn-tensor-type-to-original-text-before-tokenized-in-pytorch | python, pytorch, tensor, huggingface-transformers | 1,656,928,000 |
se_79595922 | stackoverflow | MACHINE_LEARNING | Fine-tuning a model with the Trainer API | TypeError: object of type 'NoneType' has no len() | Fine-tuning a model with the Trainer API | TypeError: object of type 'NoneType' has no len()
I am using hugging face Trainer API.
transformers version==4.31.0
torch==2.0.1
accelerate==0.27.0
I'm trying to fine-tune a TimeSformer model for video classification using the Hugging Face Transformers library. When I... | https://stackoverflow.com/questions/79595922/fine-tuning-a-model-with-the-trainer-api-typeerror-object-of-type-nonetype | python, machine-learning, pytorch, huggingface-transformers, huggingface-trainer | 1,745,822,620 |
se_74925031 | stackoverflow | MACHINE_LEARNING | Runtime Error while Saving a PyTorch Model: "File /path/to/be/saved Cannot Be Opened" | Runtime Error while Saving a PyTorch Model: "File /path/to/be/saved Cannot Be Opened"
I run a CNN model on CIFAR-10 using PyTorch and use the official PyTorch tutorial to save a general checkpoint.
When the training and testing is completed I pass the last epoch to this save_model function.
def save_model(ep... | https://stackoverflow.com/questions/74925031/runtime-error-while-saving-a-pytorch-model-file-path-to-be-saved-cannot-be-op | python, pytorch | 1,672,103,307 |
se_70269663 | stackoverflow | MACHINE_LEARNING | How to efficiently implement a non-fully connected Linear Layer in PyTorch? | How to efficiently implement a non-fully connected Linear Layer in PyTorch?
I made an example diagram of a scaled down version of what I'm trying to implement:
So the top two input nodes are only fully connected to the top three output nodes, and the same design applies to the bottom two nodes. So far I've come up wi... | https://stackoverflow.com/questions/70269663/how-to-efficiently-implement-a-non-fully-connected-linear-layer-in-pytorch | python, machine-learning, pytorch, sparse-matrix | 1,638,934,866 |
se_79589222 | stackoverflow | MACHINE_LEARNING | How do I make torch.ones(...) work inside a traced wrapper model during symbolic_trace()? | How do I make torch.ones(...) work inside a traced wrapper model during symbolic_trace()?
Thanks for giving this a read...
I am getting going with PyTorch. I’m building a tool that wraps HuggingFace models in a custom WrappedModel so I can trace their execution using torch.fx.symbolic_trace. The goal is to analyze the... | https://stackoverflow.com/questions/79589222/how-do-i-make-torch-ones-work-inside-a-traced-wrapper-model-during-symbolic | python, pytorch, huggingface-transformers, torch | 1,745,431,036 |
se_79582585 | stackoverflow | MACHINE_LEARNING | RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:1 and cuda:0! during training on multi-GPU setup | RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:1 and cuda:0! during training on multi-GPU setup
I'm facing an issue when training a model using PEFT and LoRA on a multi-GPU setup with PyTorch and Hugging Face Transformers. The error I get is:
RuntimeError: Expected al... | https://stackoverflow.com/questions/79582585/runtimeerror-expected-all-tensors-to-be-on-the-same-device-but-found-at-least | python, pytorch, huggingface-transformers, multi-gpu, peft | 1,745,079,032 |
se_79417386 | stackoverflow | MACHINE_LEARNING | Pytorch Convolution Network: problem with floating point type | Pytorch Convolution Network: problem with floating point type
I'm trying to train the CV-model with standard MNIST-data:
import torch
from torchvision.datasets import MNIST
import torchvision.transforms as transforms
img_transforms = transforms.Compose([
transforms.ToTensor(),
transforms.Normalize((0.13... | https://stackoverflow.com/questions/79417386/pytorch-convolution-network-problem-with-floating-point-type | python, pytorch, floating-point | 1,738,834,484 |
se_79419018 | stackoverflow | MACHINE_LEARNING | YOLOv8 Final Detection Head Still Outputs (1, 7, 8400) Instead of (1, 8, 8400) for 3 Classes | YOLOv8 Final Detection Head Still Outputs (1, 7, 8400) Instead of (1, 8, 8400) for 3 Classes
I trained a YOLOv8 detection model with 3 classes, but the raw forward pass still shows a final detect output of (1, 7, 8400) instead of (1, 8, 8400).
What I’ve Done:
Checked my data.yaml:
train: path/to/train/images
val: path... | https://stackoverflow.com/questions/79419018/yolov8-final-detection-head-still-outputs-1-7-8400-instead-of-1-8-8400-f | machine-learning, deep-learning, pytorch, yolov8, ultralytics | 1,738,867,161 |
se_79537716 | stackoverflow | MACHINE_LEARNING | conda cuda enabled pytorch installation problem | conda cuda enabled pytorch installation problem
im getting this problem where i have installed pytorch following these steps (https://medium.com/@harunijaz/a-step-by-step-guide-to-installing-cuda-with-pytorch-in-conda-on-windows-verifying-via-console-9ba4cd5ccbef) exactly, but i can't get the cuda env to recognise the... | https://stackoverflow.com/questions/79537716/conda-cuda-enabled-pytorch-installation-problem | python, pytorch, conda, installation-package | 1,743,044,158 |
se_79591629 | stackoverflow | MACHINE_LEARNING | Torch tensor dataloader shape issue | Torch tensor dataloader shape issue
I have a simple application of torch.DataLoader that gets a nice performance boost. It's created by the tensor_loader in the following example.
from torch.utils.data import DataLoader, TensorDataset, BatchSampler, RandomSampler
import numpy as np
import pandas as pd
def tensor_load... | https://stackoverflow.com/questions/79591629/torch-tensor-dataloader-shape-issue | python, pytorch, pytorch-dataloader | 1,745,541,073 |
se_54058716 | stackoverflow | MACHINE_LEARNING | How to pre-load numpy data into a buffer like io.BytesIO to make it seekable? | How to pre-load numpy data into a buffer like io.BytesIO to make it seekable?
Following function basically returns numpy.ndarray
def getimage(id):
img = self.coco.loadImgs(id)
I = io.imread(img['coco_url'])
return I #returns 'numpy.ndarray'
The getimage function being called from main:
x = l... | https://stackoverflow.com/questions/54058716/how-to-pre-load-numpy-data-into-a-buffer-like-io-bytesio-to-make-it-seekable | python, numpy, pytorch, bytesio | 1,546,750,029 |
se_72476390 | stackoverflow | MACHINE_LEARNING | How to do constrained optimization in PyTorch? | How to do constrained optimization in PyTorch?
I'm studying Pytorch and I'm trying to construct a code to get the maximum likelihood estimates.
I would like to put some constrains into optimization process to contemplate the parameter space, but I did not find something like this (in a easy way) in Pytorch.
For exampl... | https://stackoverflow.com/questions/72476390/how-to-do-constrained-optimization-in-pytorch | python, optimization, pytorch, mle | 1,654,173,408 |
se_69694093 | stackoverflow | MACHINE_LEARNING | GPU is not available for Pytorch | GPU is not available for Pytorch
I installed Anaconda, CUDA, and PyTorch today, and I can't access my GPU (RTX 2070) in torch. I followed all of installation steps and PyTorch works fine otherwise, but when I try to access the GPU either in shell or in script I get
>>> import torch
>>> torch.cuda.is_available()
False
... | https://stackoverflow.com/questions/69694093/gpu-is-not-available-for-pytorch | python, pytorch, anaconda, conda | 1,635,052,852 |
se_76004437 | stackoverflow | MACHINE_LEARNING | Elegant way to get subtensor by indices in pytorch? | Elegant way to get subtensor by indices in pytorch?
I'm trying to find an elegant way of getting a tensor, containing a list of specific subtensors in pytorch.
Let's say I have a torch tensor x of size [B, W, H, C]. I check a kind of threshold condition on the channels, which gives me a tensor cond of size [B, W, H] f... | https://stackoverflow.com/questions/76004437/elegant-way-to-get-subtensor-by-indices-in-pytorch | python, indexing, pytorch | 1,681,382,125 |
se_78008119 | stackoverflow | MACHINE_LEARNING | Huggingface transformer train function throwing Device() received an invalid combination of arguments | Huggingface transformer train function throwing Device() received an invalid combination of arguments
I was trying to train a model with peft qLora training. Lora config and peft training args are like below:
lora_config = LoraConfig(
r=8,
lora_alpha=16,
target_modules=[
"q_proj",
"k_proj",... | https://stackoverflow.com/questions/78008119/huggingface-transformer-train-function-throwing-device-received-an-invalid-com | pytorch, huggingface-transformers, large-language-model, llama, peft | 1,708,094,395 |
se_79583654 | stackoverflow | MACHINE_LEARNING | Logits Don't Change in a Custom Reimplementation of a CLIP model [PyTorch] | Logits Don't Change in a Custom Reimplementation of a CLIP model [PyTorch]
The problem
The similarity scores are almost the same for texts that describe both a photo of a cat and a dog (the photo is of a cat).
Cat similarity: tensor([[-3.5724]], grad_fn=<MulBackward0>)
Dog similarity: tensor([[-3.4155]], grad_fn=<... | https://stackoverflow.com/questions/79583654/logits-dont-change-in-a-custom-reimplementation-of-a-clip-model-pytorch | python, deep-learning, pytorch, artificial-intelligence, transformer-model | 1,745,174,763 |
se_78347092 | stackoverflow | MACHINE_LEARNING | Timm throwing HuggingFace Hub not installed error when HFhub is installed | Timm throwing HuggingFace Hub not installed error when HFhub is installed
I'm trying to create the convit_base.fb_in1k model via timm. When I call timm.create_model('convit_base.fb_in1k', pretrained=True), I get a RuntimeError: Hugging Face hub model specified but package not installed. Run 'pip install huggingface_hu... | https://stackoverflow.com/questions/78347092/timm-throwing-huggingface-hub-not-installed-error-when-hfhub-is-installed | python, pytorch, huggingface-transformers, huggingface-hub | 1,713,440,018 |
se_58448861 | stackoverflow | MACHINE_LEARNING | Is there a method to vectorize applying a function to every element of a Tensor | Is there a method to vectorize applying a function to every element of a Tensor
I want to implement an update rule in an optimization procedure. I wanted to vectorize it using pytorch functions to improve time complexity. Possibly run on a GPU.
The update rule is like
u[i][j] = multiplier*NORM(Q.column(i)-Q.column(j... | https://stackoverflow.com/questions/58448861/is-there-a-method-to-vectorize-applying-a-function-to-every-element-of-a-tensor | vectorization, pytorch | 1,571,394,068 |
se_79583142 | stackoverflow | MACHINE_LEARNING | Broadcasting a [B, 1] tensor to apply a shift to a specific channel in PyTorch | Broadcasting a [B, 1] tensor to apply a shift to a specific channel in PyTorch
I have a tensor p of shape (B, 3, N) in PyTorch:
# 2 batches, 3 channels (x, y, z), 5 points
p = torch.rand(2, 3, 5, requires_grad=True)
"""
p: tensor([[[0.8365, 0.0505, 0.4208, 0.7465, 0.6843],
[0.9922, 0.2684, 0.6898, 0.3983, 0.4... | https://stackoverflow.com/questions/79583142/broadcasting-a-b-1-tensor-to-apply-a-shift-to-a-specific-channel-in-pytorch | python, pytorch | 1,745,135,085 |
se_77436931 | stackoverflow | MACHINE_LEARNING | PyTorch and Transformers training fails on cuda devices | PyTorch and Transformers training fails on cuda devices
So I have a mix of PyTorch and Transformers code that loads my custom dataset, processes it, downloads a TinyLlama model, then finetunes that model with the processed dataset.
It works fine on cpu, but when i set the device to "cuda" it fails with the following:
... | https://stackoverflow.com/questions/77436931/pytorch-and-transformers-training-fails-on-cuda-devices | pytorch, huggingface-transformers, huggingface-datasets | 1,699,348,715 |
se_60247432 | stackoverflow | MACHINE_LEARNING | No such operator torchvision::nms | No such operator torchvision::nms
When I try to run yoloV3 detect,it happend the error
op = torch._C._jit_get_operation(qualified_op_name)
RuntimeError: No such operator torchvision::nms
Though this code is the source code of torchvision ,I try sevaral time to correct the code by the tips with failure. | https://stackoverflow.com/questions/60247432/no-such-operator-torchvisionnms | pytorch, torchvision | 1,581,848,001 |
se_79148523 | stackoverflow | MACHINE_LEARNING | Try to install xformer, but it automatically upgrade my torch and its liability. How to fix it? | Try to install xformer, but it automatically upgrade my torch and its liability. How to fix it?
As the xformer upgraded, it also provid more support to the newest version of pytorch. So when try to install xformer from pip:
pip install xformer
It always try to upgrade the pytorch, which I don't want to.
I tried to ch... | https://stackoverflow.com/questions/79148523/try-to-install-xformer-but-it-automatically-upgrade-my-torch-and-its-liability | installation, pytorch, pip | 1,730,474,237 |
se_79582481 | stackoverflow | MACHINE_LEARNING | Torch gradient estimates disagreeing with analytic and perturbation approximated gradients | Torch gradient estimates disagreeing with analytic and perturbation approximated gradients
I'm faced with a problem where as the title says I'm having trouble with the torch package's built in automatic differentiation algorithms (or my usage?). I think it was meant to be used on mini-batches in my assignment but it s... | https://stackoverflow.com/questions/79582481/torch-gradient-estimates-disagreeing-with-analytic-and-perturbation-approximated | deep-learning, pytorch, neural-network, gradient-descent | 1,745,071,934 |
se_79580250 | stackoverflow | MACHINE_LEARNING | How can I export an encoder-decoder PyTorch model into a single ONNX file? | How can I export an encoder-decoder PyTorch model into a single ONNX file?
I converted the PyTorch model Helsinki-NLP/opus-mt-fr-en (HuggingFace), which is an encoder-decoder model for machine translation, to ONNX using this script:
import os
from optimum.onnxruntime import ORTModelForSeq2SeqLM
from transformers impor... | https://stackoverflow.com/questions/79580250/how-can-i-export-an-encoder-decoder-pytorch-model-into-a-single-onnx-file | python, pytorch, huggingface-transformers, onnx, machine-translation | 1,744,934,365 |
se_79283584 | stackoverflow | MACHINE_LEARNING | What is the most efficient way to randomly pick one positive location within a large binary mask image in Python? | What is the most efficient way to randomly pick one positive location within a large binary mask image in Python?
I am writing a custom image data loading function to randomly crop part of a large image according to its binary mask. The function will be used in PyTorch dataloader so I want it to be as fast and memory-... | https://stackoverflow.com/questions/79283584/what-is-the-most-efficient-way-to-randomly-pick-one-positive-location-within-a-l | python, numpy, performance, image-processing, pytorch | 1,734,319,130 |
se_79578968 | stackoverflow | MACHINE_LEARNING | What happens in Pytorch nn.Linear | What happens in Pytorch nn.Linear
As I understand, nn.Linear from pyTorch works as matrix multiplication. Mathematically,
[W U][x h]^T = Wx + Uh,
but when using nn.Linear, the following two are not equivalent
Wf = nn.Linear(x_size, o_size)
Uf = nn.Linear(h_size, o_size)
Wf(x) + Uf(h)
and
W = nn.Linear(x_size + h_size... | https://stackoverflow.com/questions/79578968/what-happens-in-pytorch-nn-linear | pytorch | 1,744,883,842 |
se_79575684 | stackoverflow | MACHINE_LEARNING | PyTorchMetrics Mean Absolute Percentage Error extremely high value | PyTorchMetrics Mean Absolute Percentage Error extremely high value
I am using PyTorch for a face recognition coursework and I have to calculate the MAPE value.
My first attempt was with torchmetrics.MeanAbsolutePercentageError class, but the result doesn't make sense.
For this reason I wrote a function to calculate it... | https://stackoverflow.com/questions/79575684/pytorchmetrics-mean-absolute-percentage-error-extremely-high-value | python, pytorch, torchmetrics | 1,744,736,605 |
se_70043645 | stackoverflow | MACHINE_LEARNING | How to convert from tensor to float | How to convert from tensor to float
I am having a list of tensors I want to convert to floating points how can I do it. I have tried using .item but it is not working. I am getting ValueError: only one element tensors can be converted to Python scalars.
tensor([[12.1834, 4.9616, 7.7913],
[ 8.9394, 8.5784, ... | https://stackoverflow.com/questions/70043645/how-to-convert-from-tensor-to-float | python, tensorflow, pytorch, tensor, torch | 1,637,388,382 |
se_79577327 | stackoverflow | MACHINE_LEARNING | Reinforcement learning Atari video recording crashes | Reinforcement learning Atari video recording crashes
I am learning Reinforcement Learning and picked the Atari Breakout environment to learn. I have trained the neural nets, and now am trying to create some videos to visualize the results.
I am using the code below to save the video in MP4 format:
import os
os.enviro... | https://stackoverflow.com/questions/79577327/reinforcement-learning-atari-video-recording-crashes | tensorflow, pytorch, reinforcement-learning | 1,744,811,398 |
se_75134246 | stackoverflow | MACHINE_LEARNING | No module named 'mmcv._ext' | No module named 'mmcv._ext'
Tried to train the model but got the mmcv error
No module named 'mmcv._ext'
mmcv library is already installed and imported
mmcv version = 1.4.0
Cuda version = 10.0
Any suggestions to fix the issue?? | https://stackoverflow.com/questions/75134246/no-module-named-mmcv-ext | python, pytorch, openmmlab | 1,673,872,134 |
se_79571227 | stackoverflow | MACHINE_LEARNING | DIfference in variable values in jax non-jit runtime and jit transformed runtime | DIfference in variable values in jax non-jit runtime and jit transformed runtime
I have a deep learning mode which I am running in the jit transformed manner by:
my_function_checked = checkify.checkify(model.apply)
model_jitted = jax.jit(my_function_checked)
err, pred = model_jitted({"params": params}, batch, ... | https://stackoverflow.com/questions/79571227/difference-in-variable-values-in-jax-non-jit-runtime-and-jit-transformed-runtime | python, deep-learning, pytorch, artificial-intelligence, jax | 1,744,522,432 |
se_52420385 | stackoverflow | MACHINE_LEARNING | RuntimeError: cuda runtime error (30) : unknown error at torch/csrc/cuda/Module.cpp:32 | RuntimeError: cuda runtime error (30) : unknown error at torch/csrc/cuda/Module.cpp:32
using config:
'CONFIG_NAME': 'stageI',
'CUDA': True,
'DATASET_NAME': 'coco',
'DATA_DIR': '/home/anwar/Documents/StackGAN-Pytorch-
master/data/coco',
'EMBEDDING_TYPE': 'cnn-rnn',
'G... | https://stackoverflow.com/questions/52420385/runtimeerror-cuda-runtime-error-30-unknown-error-at-torch-csrc-cuda-module | python, python-2.7, pytorch | 1,537,430,702 |
se_79574117 | stackoverflow | MACHINE_LEARNING | SGLang server fails on launch due to cuda_fp8.h missing even with --disable-cuda-graph and prebuilt flashinfer wheel | SGLang server fails on launch due to cuda_fp8.h missing even with --disable-cuda-graph and prebuilt flashinfer wheel
I am trying to launch the SGLang server using python -m sglang.launch_server ... but it consistently fails during the "Capture cuda graph" phase. The error indicates a failure during Just-In-Time (JIT) ... | https://stackoverflow.com/questions/79574117/sglang-server-fails-on-launch-due-to-cuda-fp8-h-missing-even-with-disable-cuda | machine-learning, deep-learning, pytorch, sglang | 1,744,670,379 |
se_79573889 | stackoverflow | MACHINE_LEARNING | Running DeepSeek-V3 inference without GPU (on CPU only) | Running DeepSeek-V3 inference without GPU (on CPU only)
I am trying to run the DeepSeek-V3 model inference on a remote machine (SSH). This machine does not have any GPU, but has many CPU cores.
1rst method/
I try to run the model inference using the DeepSeek-Infer Demo method:
generate.py --ckpt-path /path/to/DeepSee... | https://stackoverflow.com/questions/79573889/running-deepseek-v3-inference-without-gpu-on-cpu-only | python, pytorch, huggingface-transformers, huggingface, deepseek | 1,744,659,359 |
se_79573774 | stackoverflow | MACHINE_LEARNING | RecursionError when using Opacus PrivacyEngine with PyTorch Lightning: maximum recursion depth exceeded | RecursionError when using Opacus PrivacyEngine with PyTorch Lightning: maximum recursion depth exceeded
I'm implementing a differentially private recommendation system using PyTorch Lightning and Opacus, but I'm encountering a RecursionError during training. Here's my setup:
Problem
When I run my DPModel (which wraps ... | https://stackoverflow.com/questions/79573774/recursionerror-when-using-opacus-privacyengine-with-pytorch-lightning-maximum-r | pytorch, pytorch-lightning | 1,744,654,160 |
se_79566341 | stackoverflow | MACHINE_LEARNING | Run Time of 2 for loops with Gradient calculation | Run Time of 2 for loops with Gradient calculation
I am trying to run the following code:
for ie in range(100):
energy = torch.tensor([.1 + .1 * ie], dtype = torch.float32, requires_grad = True)
xe = .5 + 20 * (torch.log(energy) - log_01) / (log_10 - log_01) #(log_ parts are some constants)
xe2 = xe * xe
... | https://stackoverflow.com/questions/79566341/run-time-of-2-for-loops-with-gradient-calculation | python, optimization, pytorch, runtime, gradient | 1,744,279,639 |
se_79568762 | stackoverflow | MACHINE_LEARNING | I keep getting this error, cuda available 'RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu | I keep getting this error, cuda available 'RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu
I'm training a transformer model using RLlib's PPO algorithm, but I encounter a device mismatch error:
RuntimeError: Expected all tensors to be on the same device,... | https://stackoverflow.com/questions/79568762/i-keep-getting-this-error-cuda-available-runtimeerror-expected-all-tensors-to | python, pytorch, reinforcement-learning, transformer-model, rllib | 1,744,371,704 |
se_70308466 | stackoverflow | MACHINE_LEARNING | Why are weight matrices shared between embedding layers in 'Attention is All You Need' paper? | Why are weight matrices shared between embedding layers in 'Attention is All You Need' paper?
I am using the Transformer module in pytorch from the paper "Attention is All You Need". On page 5, the authors state that
In our model, we share the same weight matrix between the two embedding layers and the pre-so... | https://stackoverflow.com/questions/70308466/why-are-weight-matrices-shared-between-embedding-layers-in-attention-is-all-you | nlp, pytorch, word-embedding, transformer-model | 1,639,158,171 |
se_79542733 | stackoverflow | MACHINE_LEARNING | Why do we reshape key, query, and value tensors in multi-head attention? | Why do we reshape key, query, and value tensors in multi-head attention?
In my PyTorch implementation of multi-head attention, i have those in __init__()
class MultiHeadAttentionLayer(nn.Module):
def __init__(self,d_in,d_out,context_length,dropout,num_heads,use_bias=False):
super().__init__()
self.... | https://stackoverflow.com/questions/79542733/why-do-we-reshape-key-query-and-value-tensors-in-multi-head-attention | python, pytorch, neural-network, tensor, multihead-attention | 1,743,217,137 |
se_72094088 | stackoverflow | MACHINE_LEARNING | Problems encountered in the use of torch.corrcoef in the case of origin | Problems encountered in the use of torch.corrcoef in the case of origin
In pytorch(1.10), we can use torch.corrcoef to Estimates the Pearson product-moment correlation coefficient matrix.
But there is an obvious problem, when a row is all 0, there will be a nan value, how can I modify it to solve it, I think I can mak... | https://stackoverflow.com/questions/72094088/problems-encountered-in-the-use-of-torch-corrcoef-in-the-case-of-origin | python, pytorch | 1,651,542,697 |
se_79570067 | stackoverflow | MACHINE_LEARNING | Why PyTorch Linear module backward faster than forward? | Why PyTorch Linear module backward faster than forward?
I found the PyTorch's matmul backward is slightly faster than forward.
I think it is intuitive, because for A*B=C, forward propagate this operator only takes one matrix multiplication.
Compared to two matrix multiplications, dC/dA and dC/dB in backward propagate,... | https://stackoverflow.com/questions/79570067/why-pytorch-linear-module-backward-faster-than-forward | pytorch | 1,744,436,116 |
se_79022620 | stackoverflow | MACHINE_LEARNING | I want to strictly use Tensor Cores for running inference of a pretrained full precision CNN model in Pytorch | I want to strictly use Tensor Cores for running inference of a pretrained full precision CNN model in Pytorch
I have been analyzing the maximum throughput I can get from my device for a specific CNN model using a GPU. My GPU has CUDA cores as well as Tensor cores. So I want to simultaneous run the model on both the ty... | https://stackoverflow.com/questions/79022620/i-want-to-strictly-use-tensor-cores-for-running-inference-of-a-pretrained-full-p | pytorch, conv-neural-network, tensor, automatic-mixed-precision | 1,727,263,587 |
se_43781526 | stackoverflow | MACHINE_LEARNING | Pytorch, TypeError: object() takes no parameters | Pytorch, TypeError: object() takes no parameters
This is probably a beginner question, but nevertheless: When running an image classifier build with pytorch, I get this error:
Traceback (most recent call last):
File "/pytorch/kanji_torch.py", line 47, in <module>
network = Network()
File "/pytorch/kanji_torch.p... | https://stackoverflow.com/questions/43781526/pytorch-typeerror-object-takes-no-parameters | python, machine-learning, pytorch, neural-network, typeerror | 1,493,897,041 |
se_76084214 | stackoverflow | MACHINE_LEARNING | What is the recommended number of threads for PyTorch relative to available CPU cores? | What is the recommended number of threads for PyTorch relative to available CPU cores?
First I want to say that I don't have much experience with pytorch, ML, NLP and other related topics, so I may confuse some concepts. Sorry.
I downloaded few models from Hugging Face, organized them in one Python script and started ... | https://stackoverflow.com/questions/76084214/what-is-the-recommended-number-of-threads-for-pytorch-relative-to-available-cpu | python, pytorch, parallel-processing, huggingface-transformers, huggingface | 1,682,244,173 |
se_79561884 | stackoverflow | MACHINE_LEARNING | How to perform global structured pruning in PyTorch | How to perform global structured pruning in PyTorch
I am training on CIFAR10 the following simple CNN
class SimpleCNN(nn.Module):
def __init__(self):
super().__init__()
self.conv1 = nn.Conv2d(3, 32, kernel_size=3, padding=1)
self.conv2 = nn.Conv2d(32, 64, kernel_size=3, padding=1)
s... | https://stackoverflow.com/questions/79561884/how-to-perform-global-structured-pruning-in-pytorch | python, machine-learning, deep-learning, pytorch, pruning | 1,744,111,216 |
se_79562213 | stackoverflow | MACHINE_LEARNING | Why the outputs while training and testing are different? | Why the outputs while training and testing are different?
I tried fine-tuning the LLaMA-2-7B model using the FreedomIntelligence/medical-o1-reasoning-SFT dataset in an instruction-answer format. For now, I'm intentionally overfitting the dataset to observe the training flow.
After training, when I run inference immedi... | https://stackoverflow.com/questions/79562213/why-the-outputs-while-training-and-testing-are-different | python, pytorch | 1,744,119,757 |
se_78105436 | stackoverflow | MACHINE_LEARNING | Convert PyTorch Model to Hugging Face model | Convert PyTorch Model to Hugging Face model
I have looked at a lot resources but I still have issues trying to convert a PyTorch model to a hugging face model format. I ultimately want to be able to use inference API with my custom model.
I have a "model.pt" file which I got from fine-tuning the Facebook Musicgen medi... | https://stackoverflow.com/questions/78105436/convert-pytorch-model-to-hugging-face-model | pytorch, huggingface-transformers, huggingface, huggingface-tokenizers, huggingface-hub | 1,709,615,364 |
se_79560879 | stackoverflow | MACHINE_LEARNING | Image rotation: model for angle detection using pytorch | Image rotation: model for angle detection using pytorch
Basically I am trying to create a model that will detect angle on which a specific image is rotated. Also I have a dataset of 1500 documents resulting with images rotated on
random.sample([0, 90, -90, 180], 2)
and each of this angles has variation of
random.unif... | https://stackoverflow.com/questions/79560879/image-rotation-model-for-angle-detection-using-pytorch | python, machine-learning, pytorch | 1,744,064,443 |
se_60891052 | stackoverflow | MACHINE_LEARNING | How can I trim a tensor based on a mask with PyTorch? | How can I trim a tensor based on a mask with PyTorch?
I have a tensor inp, which has a size of: torch.Size([4, 122, 161]).
I also have a mask with a size of: torch.Size([4, 122]).
Each element in my mask looks something like:
tensor([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0.... | https://stackoverflow.com/questions/60891052/how-can-i-trim-a-tensor-based-on-a-mask-with-pytorch | python, pytorch | 1,585,329,747 |
se_69357881 | stackoverflow | MACHINE_LEARNING | How to remove the model of transformers in GPU memory | How to remove the model of transformers in GPU memory
from transformers import CTRLTokenizer, TFCTRLLMHeadModel
tokenizer_ctrl = CTRLTokenizer.from_pretrained('ctrl', cache_dir='./cache', local_files_only=True)
model_ctrl = TFCTRLLMHeadModel.from_pretrained('ctrl', cache_dir='./cache', local_files_only=True)
print(tok... | https://stackoverflow.com/questions/69357881/how-to-remove-the-model-of-transformers-in-gpu-memory | pytorch, huggingface-transformers | 1,632,815,978 |
se_79095041 | stackoverflow | MACHINE_LEARNING | detectron2 installation - No module named 'torch' | detectron2 installation - No module named 'torch'
I am trying to install detectron2 on ubuntu and face a weird python dependency problem. In short - pytorch is installed (with pip), torchvision is installed (with pip), but when I run
pip install 'git+https://github.com/facebookresearch/detectron2.git'
I get e... | https://stackoverflow.com/questions/79095041/detectron2-installation-no-module-named-torch | python, pytorch | 1,729,097,200 |
se_76059654 | stackoverflow | MACHINE_LEARNING | getting a error when running GPTNeoXForCausalLM from Transformers Library: NameError: name 'init_empty_weights' is not defined | getting a error when running GPTNeoXForCausalLM from Transformers Library: NameError: name 'init_empty_weights' is not defined
I'm trying to run OpenAssistant's pythia-12b model but I'm getting the following error:
NameError: name 'init_empty_weights' is not defined
I have Accelerate installed, and I'm runnin... | https://stackoverflow.com/questions/76059654/getting-a-error-when-running-gptneoxforcausallm-from-transformers-library-namee | pytorch, huggingface-transformers | 1,681,949,369 |
se_58151507 | stackoverflow | MACHINE_LEARNING | Why Pytorch officially use mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225] to normalize images? | Why Pytorch officially use mean=[0.485, 0.456, 0.406] and std=[0.229, 0.224, 0.225] to normalize images?
In this page (https://pytorch.org/vision/stable/models.html), it says that "All pre-trained models expect input images normalized in the same way, i.e. mini-batches of 3-channel RGB images of shape (3 x H x W), whe... | https://stackoverflow.com/questions/58151507/why-pytorch-officially-use-mean-0-485-0-456-0-406-and-std-0-229-0-224-0-2 | python, pytorch, normalize | 1,569,720,664 |
se_79516939 | stackoverflow | MACHINE_LEARNING | TRITON - Strange error with matrix multiplication | TRITON - Strange error with matrix multiplication
I have 2 matrices P and V and when I take their dot product with triton I get results that are inconsistent with pytorch.
The P and V matrices are as follows. P is basically the softmax which is why it is mostly 0s except the final column, the result of the dot product... | https://stackoverflow.com/questions/79516939/triton-strange-error-with-matrix-multiplication | python, pytorch, matrix-multiplication, triton | 1,742,290,856 |
se_79557948 | stackoverflow | MACHINE_LEARNING | Duplicate GPU detected : rank 0 and rank 1 both on CUDA device 40 | Duplicate GPU detected : rank 0 and rank 1 both on CUDA device 40
I am trying to do QLoRA+FSDP2 on kaggle using 2x T4 gpus, this is my training script
def train_fsdp(rank, size):
torch.cuda.empty_cache()
base_model = "meta-llama/Llama-3.1-8B"
bnb_config = BitsAndBytesConfig(------)
model = AutoModelFor... | https://stackoverflow.com/questions/79557948/duplicate-gpu-detected-rank-0-and-rank-1-both-on-cuda-device-40 | machine-learning, pytorch | 1,743,927,036 |
se_61323621 | stackoverflow | MACHINE_LEARNING | How to understand hidden_states of the returns in BertModel? | How to understand hidden_states of the returns in BertModel?
Returns last_hidden_state (torch.FloatTensor of shape (batch_size,
sequence_length, hidden_size)): Sequence of hidden-states at the
output of the last layer of the model.
pooler_output (torch.FloatTensor: of shape (batch_size, hidden_size)):
Last layer hidde... | https://stackoverflow.com/questions/61323621/how-to-understand-hidden-states-of-the-returns-in-bertmodel | nlp, pytorch, huggingface-transformers, bert-language-model, electrate | 1,587,389,197 |
se_79556482 | stackoverflow | MACHINE_LEARNING | How to validate search terms when using embedding to look for objects in images | How to validate search terms when using embedding to look for objects in images
I have a search on my site that does both tradition full text search and searches using embeddings. So, for example, when you search 'red balloon' I want both the text and image results. The problem is that not all search terms make sense ... | https://stackoverflow.com/questions/79556482/how-to-validate-search-terms-when-using-embedding-to-look-for-objects-in-images | python, pytorch, knn, embedding | 1,743,819,316 |
se_75709831 | stackoverflow | MACHINE_LEARNING | Zero Accuracy in Sentiment Analysis FFNN Model (Pytorch) | Zero Accuracy in Sentiment Analysis FFNN Model (Pytorch)
I'm constructing a feedforward neural net (FFNN) for binary sentiment classification using movie review dataset. It's a simplified task with only two class labels, i.e., positive (1) and negative (0). It FFNN makes word embeddings, averages them, runs them throu... | https://stackoverflow.com/questions/75709831/zero-accuracy-in-sentiment-analysis-ffnn-model-pytorch | python, deep-learning, pytorch, nlp, sentiment-analysis | 1,678,572,297 |
se_48377214 | stackoverflow | MACHINE_LEARNING | RuntimeError: dimension out of range (expected to be in range of [-1, 0], but got 1) | RuntimeError: dimension out of range (expected to be in range of [-1, 0], but got 1)
Im using a Pytorch Unet model to which i am feeding in a image as input and along with that i am feeding the label as the input image mask and traning the dataset on it.
The Unet model i have picked up from somewhere else, and i am us... | https://stackoverflow.com/questions/48377214/runtimeerror-dimension-out-of-range-expected-to-be-in-range-of-1-0-but-go | python, machine-learning, pytorch | 1,516,609,092 |
se_79554290 | stackoverflow | MACHINE_LEARNING | Debug jax In vscode | Debug jax In vscode
Why can't I use a vscode debugger to debug jax code, specifically pure functions. I understand that they provide their own framework for debugging but vscode debugger is quite comfortable. Is this because vscode debugger in the first attempt captures compile time? | https://stackoverflow.com/questions/79554290/debug-jax-in-vscode | pytorch, jax, flax | 1,743,729,527 |
se_79512576 | stackoverflow | MACHINE_LEARNING | Pytorch nn model not learning anymore after going through the first dataset batch | Pytorch nn model not learning anymore after going through the first dataset batch
I've written a code which goes through different datasets grouped in labels and lets the created model learn each dataset/label separately.
The problem now is that the model learns the first dataset perfectly well, but after that only le... | https://stackoverflow.com/questions/79512576/pytorch-nn-model-not-learning-anymore-after-going-through-the-first-dataset-batc | deep-learning, pytorch | 1,742,129,852 |
se_79552821 | stackoverflow | MACHINE_LEARNING | Transposed convolution 2D with stride > 1 | Transposed convolution 2D with stride > 1
I was reading pytorch docs about Conv2DTranspose on https://pytorch.org/docs/stable/generated/torch.nn.ConvTranspose2d.html#torch.nn.ConvTranspose2d, and I was curious as to what happens if we increase the stride to be larger than 1. I know how transposed convolution works ... | https://stackoverflow.com/questions/79552821/transposed-convolution-2d-with-stride-1 | pytorch, conv-neural-network | 1,743,680,673 |
se_54047725 | stackoverflow | MACHINE_LEARNING | Gradually decay the weight of loss function | Gradually decay the weight of loss function
I am working with CycleGAN (pyTorch implementation) as a part of my project and I understand most of the implementation of cycleGAN.
I read the paper with the name ‘CycleGAN with better Cycles’ and I am trying to apply the modification which mentioned in the paper. One of mo... | https://stackoverflow.com/questions/54047725/gradually-decay-the-weight-of-loss-function | python, pytorch, torchvision | 1,546,646,722 |
se_77150837 | stackoverflow | MACHINE_LEARNING | Using DataParallel with two GPUs is much slower than using one GPU | Using DataParallel with two GPUs is much slower than using one GPU
Recently I've been learning Pytorch to train models using multiple GPUs, and one of the first things I started to experiment with was DataParallel (even though it's a method that's discouraged to use), and I constructed some dummy data, as well as a to... | https://stackoverflow.com/questions/77150837/using-dataparallel-with-two-gpus-is-much-slower-than-using-one-gpu | pytorch, multi-gpu, dataparallel | 1,695,303,732 |
se_79551475 | stackoverflow | MACHINE_LEARNING | PyTorch runtime error with input when using two models | PyTorch runtime error with input when using two models
I have two models. One is pretrained with YOLOv11 and detects faces and second one trained from scratch with Tensorflow converted to onnx using tf2onnx and then to pt using onnx2pytorch. Second model recognizes face. If you wondered program is supposed to take ima... | https://stackoverflow.com/questions/79551475/pytorch-runtime-error-with-input-when-using-two-models | python, pytorch, runtime-error, tensorflow2.0 | 1,743,624,308 |
se_62111599 | stackoverflow | MACHINE_LEARNING | Load data into GPU directly using PyTorch | Load data into GPU directly using PyTorch
In training loop, I load a batch of data into CPU and then transfer it to GPU:
import torch.utils as utils
train_loader = utils.data.DataLoader(train_dataset, batch_size=128, shuffle=True, num_workers=4, pin_memory=True)
for inputs, labels in train_loader:
inputs, label... | https://stackoverflow.com/questions/62111599/load-data-into-gpu-directly-using-pytorch | python-3.x, deep-learning, pytorch, gpu, dataloader | 1,590,899,452 |
se_79549110 | stackoverflow | MACHINE_LEARNING | Huggingface tokenizer: 'str' object has no attribute 'size' | Huggingface tokenizer: 'str' object has no attribute 'size'
I am trying to extract the hidden states of a transformer model:
from transformers import AutoModel
import torch
from transformers import AutoTokenizer
model_ckpt = "distilbert-base-uncased"
device = torch.device("cuda" if torch.cuda.is_avail... | https://stackoverflow.com/questions/79549110/huggingface-tokenizer-str-object-has-no-attribute-size | python, pytorch, huggingface-transformers | 1,743,538,775 |
se_75134082 | stackoverflow | MACHINE_LEARNING | Jetson nano, can use cuda in python3 terminal, but not in a file | Jetson nano, can use cuda in python3 terminal, but not in a file
If I try to use cuda on the jetson nano in the terminal:
$ python3
> > > import torch
> > > print(torch.cuda.is_available())
True
But if I start a file with the same content the output is False.
Does anyone have any idea how to fix this?
I've tried:
im... | https://stackoverflow.com/questions/75134082/jetson-nano-can-use-cuda-in-python3-terminal-but-not-in-a-file | python, pytorch, torchvision, nvidia-jetson | 1,673,871,354 |
se_79050217 | stackoverflow | MACHINE_LEARNING | Has anyone successfully converted a PyTorch-based LLM to ONNX Runtime to reduce file size? | Has anyone successfully converted a PyTorch-based LLM to ONNX Runtime to reduce file size?
I’m exploring the idea of converting PyTorch and TensorFlow models to ONNX Runtime to optimize performance and reduce file sizes. Since most large language models (LLMs) are built using PyTorch, I was wondering if anyone has suc... | https://stackoverflow.com/questions/79050217/has-anyone-successfully-converted-a-pytorch-based-llm-to-onnx-runtime-to-reduce | pytorch, large-language-model, onnx, onnxruntime | 1,727,953,201 |
se_79546578 | stackoverflow | MACHINE_LEARNING | TypeError: Dataloader object is not subscriptable | TypeError: Dataloader object is not subscriptable
I'm creating an AI model to generate density plots of crowds. When splitting the dataset into two, one for training and one for validation, I create the two data sets and try to load the datasets using torch.utils.data.DataLoader(test_set, batch_size=batch_size, shuffl... | https://stackoverflow.com/questions/79546578/typeerror-dataloader-object-is-not-subscriptable | python, machine-learning, pytorch | 1,743,433,335 |
se_65621414 | stackoverflow | MACHINE_LEARNING | How to merge two torch.utils.data dataloaders with a single operation | How to merge two torch.utils.data dataloaders with a single operation
I have two dataloaders and I would like to merge them without redefining the datasets, in my case train_dataset and val_dataset.
train_loader = DataLoader(train_dataset, batch_size = 512, drop_last=True,shuffle=True)
val_loader = DataLoader(val_data... | https://stackoverflow.com/questions/65621414/how-to-merge-two-torch-utils-data-dataloaders-with-a-single-operation | deep-learning, pytorch, dataloader | 1,610,062,185 |
se_79398991 | stackoverflow | MACHINE_LEARNING | Using Pytorch Sequential for reinforcement model without gym | Using Pytorch Sequential for reinforcement model without gym
I'm trying to play a game with AI, but I want to do it in real time. Because of that, I'm not using gym to create an environment.
I want to take a screenshot, preprocess it, then pass it through the model before updating the model based on whether or not the... | https://stackoverflow.com/questions/79398991/using-pytorch-sequential-for-reinforcement-model-without-gym | python, pytorch, conv-neural-network, artificial-intelligence, reinforcement-learning | 1,738,218,434 |
se_79285088 | stackoverflow | MACHINE_LEARNING | Masked self-attention not working as expected when each token is masking also itself | Masked self-attention not working as expected when each token is masking also itself
I was developing a self-attentive module using Pytorch's nn.MultiheadAttention (MHA). My goal was to implement a causal mask that enforces each token to attend only to the tokens before itself, excluding itself, unlike the standard au... | https://stackoverflow.com/questions/79285088/masked-self-attention-not-working-as-expected-when-each-token-is-masking-also-it | pytorch, attention-model, autoregressive-models, multihead-attention, causal-inference | 1,734,360,916 |
se_75260516 | stackoverflow | MACHINE_LEARNING | How to pass 2D attention mask to HuggingFace BertModel? | How to pass 2D attention mask to HuggingFace BertModel?
I would like to pass a directional attention mask to BertModel.forward, so that I can control which surrounding tokens each token can see during self-attention. This matrix would have to be 2D.
Here is an example with three input ids, where the first two tokens c... | https://stackoverflow.com/questions/75260516/how-to-pass-2d-attention-mask-to-huggingface-bertmodel | python, pytorch, huggingface-transformers | 1,674,835,261 |
se_79545477 | stackoverflow | MACHINE_LEARNING | What is the computetype of torch.nn.functional.linear when input is float16 or bfloat16 | What is the computetype of torch.nn.functional.linear when input is float16 or bfloat16
In following code
import torch
from torch.nn.functional import linear
a=torch.ones(2,3).type(torch.float16)
b=torch.ones(2,3).type(torch.float16)
linear(a,b)
what is the computetype of linear, fp32 or fp16 or other?
Thanks
I try t... | https://stackoverflow.com/questions/79545477/what-is-the-computetype-of-torch-nn-functional-linear-when-input-is-float16-or-b | python, pytorch | 1,743,393,949 |
se_79533110 | stackoverflow | MACHINE_LEARNING | tar.gz file in s3 bucket is not loaded in sagemaker notebook | tar.gz file in s3 bucket is not loaded in sagemaker notebook
I'm just testing AWS tools to serve using sagemaker. My current progress is that I've already created a trained model, and compressed pth, inference.py, requirement.txt, and other necessary files into tar.gz and deployed them to an s3 bucket.
$ tar -tzf bire... | https://stackoverflow.com/questions/79533110/tar-gz-file-in-s3-bucket-is-not-loaded-in-sagemaker-notebook | amazon-web-services, pytorch, zip, amazon-sagemaker | 1,742,892,526 |
se_79544819 | stackoverflow | MACHINE_LEARNING | Conversion of model weights from old Keras version to Pytorch | Conversion of model weights from old Keras version to Pytorch
I want to transfer pretrained weights from an old project on github : https://github.com/ajgallego/staff-lines-removal
The original Keras model code is:
def get_keras_autoencoder(self, input_size=256, nb_filter=96, k_size=5):
input_img = Input(shape=(1... | https://stackoverflow.com/questions/79544819/conversion-of-model-weights-from-old-keras-version-to-pytorch | python, machine-learning, keras, pytorch, computer-vision | 1,743,349,281 |
se_69543907 | stackoverflow | MACHINE_LEARNING | PyTorch `torch.no_grad` vs `torch.inference_mode` | PyTorch `torch.no_grad` vs `torch.inference_mode`
PyTorch has new functionality torch.inference_mode as of v1.9 which is "analogous to torch.no_grad... Code run under this mode gets better performance by disabling view tracking and version counter bumps."
If I am just evaluating my model at test time (i.e. not trainin... | https://stackoverflow.com/questions/69543907/pytorch-torch-no-grad-vs-torch-inference-mode | machine-learning, pytorch, artificial-intelligence, gradient-descent, inference | 1,634,055,683 |
se_59390160 | stackoverflow | MACHINE_LEARNING | RuntimeError: Error(s) in loading state_dict for Generator: size mismatch for weights and biases using Pytorch | RuntimeError: Error(s) in loading state_dict for Generator: size mismatch for weights and biases using Pytorch
I'm training a 3D-GAN to generate MRI volumes. I defined my model as follows:
###### Definition of the generator ######
class Generator(nn.Module):
def __init__(self, ngpu):
#super() makes Generator a ... | https://stackoverflow.com/questions/59390160/runtimeerror-errors-in-loading-state-dict-for-generator-size-mismatch-for-we | python, pytorch, generative-adversarial-network | 1,576,665,420 |
se_70348160 | stackoverflow | MACHINE_LEARNING | Tensor Operation and gradient | Tensor Operation and gradient
I was going some tutorials on youtube where below code sample was used to explain derivatives
Create tensors.
x = torch.tensor(3.)
w = torch.tensor(4., requires_grad=True)
b = torch.tensor(5., requires_grad=True)
x, w, b
Arithmetic operations
y = w * x + b
y
... | https://stackoverflow.com/questions/70348160/tensor-operation-and-gradient | deep-learning, pytorch, gradient, tensor, derivative | 1,639,481,520 |
se_79540216 | stackoverflow | MACHINE_LEARNING | Why does the square of a complex tensor with no imaginary part yields a result with an imaginary part? | Why does the square of a complex tensor with no imaginary part yields a result with an imaginary part?
I have a complex tensor: tensor1 = tensor([0.0000+0.j, -106990.0794+0.j], device='cuda:1', dtype=torch.complex128)
The both elements have no imaginary part (0.j), however, when squaring the variable tensor1**2 it yie... | https://stackoverflow.com/questions/79540216/why-does-the-square-of-a-complex-tensor-with-no-imaginary-part-yields-a-result-w | pytorch, tensor, complex-numbers | 1,743,117,683 |
se_77802368 | stackoverflow | MACHINE_LEARNING | ValueError: The provided lr scheduler "<torch.optim.lr_scheduler.MultiStepLR object at 0x0000021897D84160>" is invalid | ValueError: The provided lr scheduler "<torch.optim.lr_scheduler.MultiStepLR object at 0x0000021897D84160>" is invalid
I encountered this error when I tried to NERF with the GPU, and this error occurred in train.fit() where the trainer is as follow:
from pytorch_lightning import LightningModule, Tr... | https://stackoverflow.com/questions/77802368/valueerror-the-provided-lr-scheduler-torch-optim-lr-scheduler-multisteplr-obj | pytorch, scheduler, pytorch-lightning | 1,704,998,617 |
se_79519426 | stackoverflow | MACHINE_LEARNING | Error When Using Batch Size Greater Than 1 in PyTorch | Error When Using Batch Size Greater Than 1 in PyTorch
I'm building a neural network to predict how an image will be partitioned during compression using VVC (Versatile Video Coding). The model takes a single Y-frame from a YUV420 image as input and uses a CSV file containing the ground truth block positions and sizes ... | https://stackoverflow.com/questions/79519426/error-when-using-batch-size-greater-than-1-in-pytorch | python, machine-learning, pytorch, training-data, pytorch-dataloader | 1,742,369,309 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.