Pytorch
文章平均质量分 50
乐清sss
立志成为大师的萌妹子!
展开
-
Hugging Face Model Hub 预训练模型清华镜像使用
今天遇到一个错误:OSError: Couldn’t reach server at ‘https://s3.amazonaws.com/models.huggingface.co/bert/roberta-large-config.json’ to download configuration file or configuration file is not a valid JSON file. Please check network or file content here: /users/yqs原创 2021-06-04 15:17:16 · 7725 阅读 · 5 评论 -
OSError: libcusparse.so.10: cannot open shared object file: No such file or directory
这样的问题真是遇到好几次了,记录一下。我以为我没有安装cudatoolkit,可是anaconda3目录里明明有的原因是环境变量没有添加找到你缺失的这个文件所在的目录,然后添加到环境变量里,比如我的libcusparse.so.10文件在“/users/yqsun/anaconda3/pkgs/cudatoolkit-10.2.89-hfd86e86_1/lib” 目录下编辑环境变量vim .bashrc最后面添加export LD_LIBRARY_PATH="/users/yqsu原创 2021-04-18 10:58:48 · 4653 阅读 · 0 评论 -
PyTorch知识点补全
1. 如何在 PyTorch 中设定学习率衰减(learning rate decay)很多时候我们要对学习率(learning rate)进行衰减,下面的代码示范了如何每30个epoch按10%的速率衰减:def adjust_learning_rate(optimizer, epoch): """Sets the learning rate to the initial LR decayed by 10 every 30 epochs""" lr = args.lr * (0.1 *原创 2021-04-16 14:22:53 · 672 阅读 · 0 评论 -
GPT2 throw error Using pad_token, but it is not set yet
今天使用GPT2遇到的ERROR,看了一下源码,问题在这:pytorch_transformers.tokenization_utilsclass PreTrainedTokenizer(object):......@property def pad_token(self): """ Padding token (string). Log an error if used while not having been set. """ if self._pad原创 2020-06-29 18:05:14 · 4989 阅读 · 2 评论 -
leetcode 146.LRU缓存机制 & OrderedDict
今天刷到leetcode第146题涉及到了OrderedDict的知识,记录一下运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get 和 写入数据 put 。获取数据 get(key) - 如果密钥 (key) 存在于缓存中,则获取密钥的值(总是正数),否则返回 -1。写入数据 put(key, value) - 如果密钥已经存在,则变更其数据值;如果密钥不存在,则插入该组「密钥/数据值」。当缓存容量达到上限时,它应该在写入新数据之前删原创 2020-05-25 18:23:20 · 333 阅读 · 0 评论 -
RuntimeError: Expected object of backend CUDA but got backend CPU for argument #3 'index'
使用bert时遇到的一个bug,是因为我没有把向量从cpu类型转为gpu类型,参考issue 227问题:Here is the complete error message:Traceback (most recent call last): File "app/set_expantion_eval.py", line 118, in <module> map_n=...原创 2019-12-16 19:33:46 · 3760 阅读 · 0 评论 -
使用pytorch_pretrained_bert将tensorflow模型转化为pytorch模型
BERT仓库里的模型是TensorFlow版本的,需要进行相应的转换才能在pytorch中使用在Google BERT仓库里下载需要的模型,这里使用的是中文预训练模型(chinese_L-12_H-768_A_12)下载chinese_L-12_H-768_A-12.zip后解压,里面有5个文件bert_config.jsonbert_model.ckpt.data-00000-of-0...原创 2019-12-09 15:28:48 · 5985 阅读 · 7 评论 -
Pytorch代码中的常识和一些好用的操作
最近在读一些深度学习的代码,不禁感叹别人代码的天工之作,再看看自己的代码,哇真是垃圾,有好多操作没见到过,所以也不会用,在这里做个记录,正如以人为鉴可以正衣冠…1. **kwargs**kwargs表示关键字参数,它本质上是一个dict,来看个例子:t = Train(train_iter=train_iter, dev_iter=dev_iter, test_iter=test_iter,...原创 2019-11-15 23:04:55 · 1953 阅读 · 0 评论 -
Pytorch中torch.nn.Softmax的dim参数含义
涉及到多维tensor时,对softmax的参数dim总是很迷,下面用一个例子说明import torch.nn as nnm = nn.Softmax(dim=0)n = nn.Softmax(dim=1)k = nn.Softmax(dim=2)input = torch.randn(2, 2, 3)print(input)print(m(input))print(n(inp...原创 2019-09-21 18:43:49 · 33555 阅读 · 7 评论