我是拥有 AMD GPU(RX 5700、Navi10)的悲惨生物之一。我想使用最新的 PyTorch 库在本地计算机上进行一些深度学习并停止使用云实例。
我在互联网上看到 AMD 承诺在未来 2-4 个月内支持 Navi10(1-2 年前写的帖子),但是,我不认为他们发布了“官方”支持。
我在本地计算机上安装了 ROCm,它实际上检测到我的 GPU,一切看起来都很好,这是rocminfo
输出。
我安装了必要的 PyTorch ROCm 版本,但是当我尝试运行代码时,出现以下错误。
hipErrorNoBinaryForGpu:无法找到所有当前设备的代码对象!
我想这是因为 ROCm 仍然不支持 gfx1010 或者我在这一点上迷失了。
如果有人可以提供一种使 ROCm 工作的方法(最好无需再次为 gfx1010 编译整个包)或提供像 CUDA 用户一样使用 AMD GPU 的方法,我会很高兴。
我想使用小队数据集微调 LabSE 以进行问答。我收到这个错误:
ValueError: The model did not return a loss from the inputs, only the following keys: last_hidden_state,pooler_output. For reference, the inputs it received are input_ids,token_type_ids,attention_mask.
我正在尝试使用 pytorch 微调模型。我尝试使用较小的批量大小,但只使用了 10% 的训练数据集,因为我遇到了内存分配问题。如果内存分配问题消失,则会发生此错误。老实说,我坚持了下来。你有什么提示吗?
我正在尝试使用 Huggingface 教程,但我想使用其他评估(我想自己做),所以我跳过了使用数据集的评估部分。
from datasets import load_dataset
raw_datasets = load_dataset("squad", split='train')
from transformers import BertTokenizerFast, BertModel
from transformers import AutoTokenizer
model_checkpoint = "setu4993/LaBSE"
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = BertModel.from_pretrained(model_checkpoint)
max_length = 384
stride = 128
def preprocess_training_examples(examples):
questions = [q.strip() for q in examples["question"]]
inputs = tokenizer(
questions, …
Run Code Online (Sandbox Code Playgroud) 给定 Pytorch 中的一个简单神经网络,例如:
import torch.nn as nn
net = nn.Sequential(
nn.Linear(3, 4),
nn.Sigmoid(),
nn.Linear(4, 1),
nn.Sigmoid()
).to(device)
Run Code Online (Sandbox Code Playgroud)
目标是将 Pytorchnn.Module
对象转换nn.Sequential
为 HuggingfacePreTrainedModel
对象,然后运行如下所示的代码:
import torch.nn as nn
from transformers.modeling_utils import PreTrainedModel
net = nn.Sequential(
nn.Linear(3, 4),
nn.Sigmoid(),
nn.Linear(4, 1),
nn.Sigmoid()
).to(device)
# Do something to convert the Pytorch nn.Module to the PreTrainedModel object.
shiny_model = do_some_magic(net, some_args, some_kwargs)
# Save the shiny model that is a `PreTrainedModel` object.
shiny_model.save_pretrained("shiny-model")
PreTrainedModel.from_pretrained("shiny-model")
Run Code Online (Sandbox Code Playgroud)
似乎要将任何本机 Pytorch 模型构建/转换为 …
python machine-learning pre-trained-model pytorch huggingface-transformers
我正在使用 OpenAI 的新 Whisper 模型进行 STT,RuntimeError: "slow_conv2d_cpu" not implemented for 'Half'
当我尝试运行它时,我得到了结果。
没有把握
这是完整的错误:
Traceback (most recent call last):
File "/Users/reallymemorable/git/fp-stt/2-stt.py", line 20, in <module>
result = whisper.decode(model, mel, options)
File "/opt/homebrew/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/whisper/decoding.py", line 705, in decode
result = DecodingTask(model, options).run(mel)
File "/opt/homebrew/lib/python3.10/site-packages/torch/autograd/grad_mode.py", line 27, in decorate_context
return func(*args, **kwargs)
File "/opt/homebrew/lib/python3.10/site-packages/whisper/decoding.py", line 621, in run
audio_features: Tensor = self._get_audio_features(mel) # encoder forward pass
File "/opt/homebrew/lib/python3.10/site-packages/whisper/decoding.py", line 565, in _get_audio_features
audio_features …
Run Code Online (Sandbox Code Playgroud) 我正在为 NVIDIA GPU 构建 DeepStream Docker 映像,如本链接中所述。
我安装了NVIDIA 容器工具包,原始 Dockerfile 可以运行,构建后我可以使用以下命令启动具有 GPU 支持的容器:
sudo docker run --runtime=nvidia --gpus all --name Test -it deepstream:dgpu
Run Code Online (Sandbox Code Playgroud)
问题是我想在docker build
序列期间安装 PyTorch 并使用它。一旦 PyTorch 在构建序列中导入,Found no NVIDIA driver on your system
就会出现错误:
#0 0.895 Traceback (most recent call last):
#0 0.895 File "./X.py", line 15, in <module>
#0 0.895 dummy_input = torch.randn([1, 3, 224, 224], device='cuda')
#0 0.895 File "/usr/local/lib/python3.8/dist-packages/torch/cuda/__init__.py", line 229, in _lazy_init
#0 0.895 torch._C._cuda_init()
#0 0.895 …
Run Code Online (Sandbox Code Playgroud) 我有以下代码
import transformers
from transformers import pipeline
# Load the language model pipeline
model = pipeline("text-generation", model="gpt2")
# Input sentence for generating next word predictions
input_sentence = "I enjoy walking in the"
Run Code Online (Sandbox Code Playgroud)
我只想在给定输入句子的情况下生成下一个单词,但我想查看所有可能的下一个单词及其概率的列表。任何其他LLM都可以使用,我以gpt2为例。
在代码中,我想仅为下一个单词选择前 500 个单词或前 1000 个单词建议以及每个建议单词的概率,我该怎么做?
给定huggingface上的变压器模型,如何找到最大输入序列长度?
例如,这里我想截断到模型的 max_length:tokenizer(examples["text"], padding="max_length", truncation=True)
How do I find the value of "max_length"?
我需要知道,因为我正在尝试解决此错误“要求填充到 max_length 但未提供最大长度,并且模型没有预定义的最大长度。默认为无填充。”
pytorch huggingface-transformers huggingface-tokenizers huggingface
colab:https://colab.research.google.com/drive/1poFdFYmkR_rDM5U5Z2WWjTepMQ8h vzNc?usp=sharing
HF falcon 教程有以下行:
tokenizer.pad_token = tokenizer.eos_token
Run Code Online (Sandbox Code Playgroud)
我觉得很奇怪。pad 和 eos 是相同的,但为什么首先要在它们之间做出区分呢?
请注意,这样做 pad = eos. 这意味着在微调期间,模型永远不会被训练为输出 eos(最有可能),因为 eos 被视为填充令牌并且不会反向传播:
I just observed that when I set tokenizer.pad_token = tokenizer.eos_token during training, the model won't stop generating during inference, since it was trained to not output the eos token (per discussions above).
Run Code Online (Sandbox Code Playgroud)
我看到了这个(这里https://github.com/huggingface/transformers/issues/22794):
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
Run Code Online (Sandbox Code Playgroud)
但这假设模型有 pad_token。我认为必须进行额外的检查,确保它确实具有 pad_token 的嵌入,以便不存在运行时错误(〜从嵌入“表”/矩阵提取矩阵中的类型错误)。
但如果这样做,可能需要注意初始化新令牌,以便它主导生成: https: //nlp.stanford.edu/~johnhew/vocab-expansion.html
代码:
tokenizer.pad_token = tokenizer.eos_token
Run Code Online (Sandbox Code Playgroud)
该死的,这仍然不起作用:
UserWarning: You …
Run Code Online (Sandbox Code Playgroud) machine-learning pytorch huggingface-transformers huggingface-tokenizers huggingface
PyTorch 1.12将默认的 fp32 数学更改为“最高精度”,并引入了torch.set_float32_matmul_ precision API,允许用户指定其中的精度medium
,high
并highest
用于 float32 矩阵乘法的内部精度。
从文档中,我读到选择较低的精度“可能会显着提高性能,并且在某些程序中,精度损失的影响可以忽略不计”。
1. 如何确定我的程序是否会从设置较低的精度中受益?这纯粹是经验主义吗?
同样,当使用PyTorch Lightning进行训练时,我收到以下警告:
You are using a CUDA device ('NVIDIA A100-SXM4-40GB') that has Tensor Cores. To properly utilize them, you should set `torch.set_float32_matmul_precision('medium' | 'high')`
Run Code Online (Sandbox Code Playgroud)
这似乎回答了1。(即,当你的GPU有张量核心时,使用较低的精度),但没有建议使用两个较低精度中的哪一个。
2. 如何确定使用哪个较低精度(“高”或“中”)?这纯粹是经验主义吗?建议的方法是什么?
我已经安装了PyTorch 1.7.1,并且运行得很好。但是,当我尝试运行此代码时:
import transformers
from transformers import BertTokenizer
from transformers.models.bert.modeling_bert import BertModel,BertForMaskedLM
Run Code Online (Sandbox Code Playgroud)
我有:
ModuleNotFoundError: No module named 'torch.utils._pytree'
Run Code Online (Sandbox Code Playgroud)