摘要:前言 Pytorch 由Facebook人工智能研究院于2017年推出,具有强大的GPU加速张量计算功能,并且能够自动进行微分计算,从而可以使用基于梯度的方法对模型参数进行优化。 Transformers库建立在Pytorch框架之上(Tensorflow的版本功能并不完善),我们需要通过 Pyto
阅读全文
摘要:在编写代码的过程中,相信大家肯定遇到过这样的情况:代码能够编译通过,没有语法错误,但是运行结果却不对,反复检查了很多遍,依然不知道哪里出了问题。这个时候,就需要调试程序了。 所谓调试(Debug),就是让代码一步一步慢慢执行,跟踪程序的运行过程。在调试的过程中,我们可以监控程序的每一个细节,包括变量
阅读全文
摘要:指针也是C语言中最为困难的一部分,在学习中除了要正确理解基本概念,还必须要多编程,上机调试。 计算机中所有的数据都必须放在内存中,不同类型的数据占用的字节数不一样,例如 int 占用4个字节,char 占用1个字节。为了正确地访问这些数据,必须为每个字节都编上号码,就像门牌号、身份证号一样,每个字节
阅读全文
摘要:# Example of target with class indices loss = nn.CrossEntropyLoss() input = torch.randn(3, 5, requires_grad=True) target = torch.empty(3, dtype=torch.
阅读全文
摘要:x = torch.randn(4, 4) print("x size:",x.size()) y = x.view(16) print("y size:",y.size()) z = x.view(-1, 8) # the size -1 is inferred from other dimens
阅读全文
摘要:tensor = torch.randn(2, 2) # Initially dtype=float32, device=cpu tensor.to(torch.float64) cuda0 = torch.device('cuda:0') tensor.to(cuda0) tensor.to(cu
阅读全文
摘要:https://github.com/PaddlePaddle/PaddleNLP/blob/develop/paddlenlp/data/collate.py
阅读全文
摘要:@dataclass class DataCollatorWithPadding: """ Data collator that will dynamically pad the inputs to the longest sequence in the batch. Args: tokenizer
阅读全文
摘要:DataCollatorMixin类 class DataCollatorMixin: def __call__(self, features, return_tensors=None): if return_tensors is None: return_tensors = self.return
阅读全文