letianlee / bert-jittor Goto Github PK
View Code? Open in Web Editor NEWA BERT model built with Jittor | 计图版 BERT 模型 | 计图 NLP 教程
License: Apache License 2.0
A BERT model built with Jittor | 计图版 BERT 模型 | 计图 NLP 教程
License: Apache License 2.0
Hi 您好,
我现在正在尝试学习这个仓库的代码并完成清华今年机器学期课程的作业。
我使用的输入与您基本相同,但是在运行3. 加载模型及优化器
(如下代码)的时候出现了错误
from bert_model import BertClassification, BertConfig
from jittor import optim
# 加载 BERT 模型
configuration = BertConfig()
model = BertClassification(configuration)
model.load_state_dict(jt.load("jittorhub://pretrained_bert.bin")) # 加载预训练的参数
# 加载 AdamW 优化器
optim = optim.AdamW(model.parameters(), lr=1e-5)
报错如下:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-120-5962eb72d2ee> in <module>
4 # 加载 BERT 模型
5 configuration = BertConfig()
----> 6 model = BertClassification(configuration)
7 model.load_state_dict(jt.load("jittorhub://pretrained_bert.bin")) # 加载预训练的参数
8
~/.cache/jittor/notebook/hw4/bert_model.py in __init__(self, config)
103 self.class_weight = config.class_weight
104
--> 105 self.bert = BertModel(config)
106 self.dropout = nn.Dropout(config.hidden_dropout_prob)
107 self.classifier = nn.Linear(config.hidden_size, config.num_labels)
~/.cache/jittor/notebook/hw4/bert_model.py in __init__(self, config, add_pooling_layer)
148 self.pooler = BertPooler(config) if add_pooling_layer else None
149
--> 150 self.init_weights()
151
152 def execute(
~/.cache/jittor/notebook/hw4/bert_model.py in init_weights(self)
82 def init_weights(self):
83 # Initialize weights
---> 84 self.apply(self._init_weights)
85
86 def _init_weights(self, module):
/usr/local/lib/python3.8/dist-packages/jittor/__init__.py in apply(self, func)
886 def apply(self, func):
887 for m in self.modules():
--> 888 func(m)
889
890 def load_parameters(self, params):
~/.cache/jittor/notebook/hw4/bert_model.py in _init_weights(self, module)
91 module.bias.zero_()
92 elif isinstance(module, nn.Embedding):
---> 93 module.weight.trunc_normal_(mean=0.0, std=self.config.initializer_range)
94 elif isinstance(module, nn.LayerNorm):
95 module.bias.zero_()
AttributeError: 'jittor_core.Var' object has no attribute 'trunc_normal_'
我使用的是jittor/jittor-cuda-11-1
作为docker环境中的jittor,版本为'1.2.2.59',请问这个报错跟版本有关吗?
十分感谢!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.