Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

callback变红 #164

Open
lili-li-cpu opened this issue Dec 21, 2023 · 3 comments
Open

callback变红 #164

lili-li-cpu opened this issue Dec 21, 2023 · 3 comments

Comments

@lili-li-cpu
Copy link

提问时请尽可能提供如下信息:

基本信息

  • 你使用的操作系统: win11
  • 你使用的Python版本:
  • 你使用的Pytorch版本: 1.8.2+cu111
  • 你使用的bert4torch版本: 0.2.8
  • 你加载的预训练模型:chinese-bert-wwm-ext

核心代码

# 请在此处贴上你的核心代码

输出信息

# 请在此处贴上你的调试输出
<img width="768" alt="image" src="https://github.com/Tongjilibo/bert4torch/assets/66951248/0d006ca0-63af-4b4f-800e-1bc7680447fa">


### 自我尝试
1、首先,我的代码出现了这个问题
raceback (most recent call last):
File "train.py", line 423, in
model.fit(train_dataloader, steps_per_epoch=None, epochs=epochs, callbacks=[evaluator])
File "/usr/local/lib/python3.8/dist-packages/torch4keras/model.py", line 225, in fit
self.output, self.loss, self.loss_detail = self.train_step(self.train_X, self.train_y)
File "/usr/local/lib/python3.8/dist-packages/torch4keras/model.py", line 111, in train_step
output = self._forward(train_X)
File "/usr/local/lib/python3.8/dist-packages/torch4keras/model.py", line 94, in _forward
return self.get_module().forward(*inputs, **input_kwargs)
TypeError: forward() takes 2 positional arguments but 4 were given
2、自我尝试
我在您的issue里面找到了类似问题,然后按照您说的
<img width="590" alt="image" src="https://github.com/Tongjilibo/bert4torch/assets/66951248/a2dfcb43-a201-4ec8-9347-d00827f5195e">
3、在变完版本后,出现了这个问题
<img width="454" alt="image" src="https://github.com/Tongjilibo/bert4torch/assets/66951248/4aaa5709-4388-437a-b92d-ef9fd19130c3">
Callback标红
<img width="774" alt="image" src="https://github.com/Tongjilibo/bert4torch/assets/66951248/4f436367-0b55-41e0-9fda-08a8820c2342">
谢谢,,这就是我的问题
@lili-li-cpu
Copy link
Author

Traceback (most recent call last):
File "D:/PycharmProjects/9.26-guan/project/chushi.py", line 11, in
from bert4torch.snippets import sequence_padding, Callback, ListDataset, seed_everything
ImportError: cannot import name 'Callback' from 'bert4torch.snippets' (D:\PycharmProjects\9.26-guan\bert4torch\snippets.py)
这就是当前的问题

@lili-li-cpu
Copy link
Author

并且,我后续下载了您的bert4torch最新版本,然后尝试运行casrel文件,出现了这个问题
Traceback (most recent call last):
File "D:/PycharmProjects/1221bert4torch/bert4torch-master/examples/relation_extraction/task_relation_extraction_CasRel.py", line 190, in
train_model = Model().to(device)
File "D:/PycharmProjects/1221bert4torch/bert4torch-master/examples/relation_extraction/task_relation_extraction_CasRel.py", line 141, in init
self.bert = build_transformer_model(config_path, checkpoint_path)
File "D:\anaconda3\envs\DL2\lib\site-packages\bert4torch\models.py", line 2128, in build_transformer_model
transformer = MODEL(**configs)
File "D:\anaconda3\envs\DL2\lib\site-packages\bert4torch\models.py", line 423, in init
self.embeddings = BertEmbeddings(**self.get_kw('vocab_size', 'embedding_size', 'hidden_size', 'max_position', 'segment_vocab_size',
File "D:\anaconda3\envs\DL2\lib\site-packages\bert4torch\layers.py", line 457, in init
self.word_embeddings = nn.Embedding(vocab_size, embedding_size, padding_idx=pad_token_id, device=kwargs['skip_init'])
TypeError: init() got an unexpected keyword argument 'device'
我此时用的版本仍是bert4torch==0.2.8和torch4keras==0.0.7.post3
这个是什么原因呀

@Tongjilibo
Copy link
Owner

callback问题是因为新版本新建了callback.py,原有的snipets中不再支持import callback了,我刚试了下,我提供的示例是可以跑的,还有建议用最新版~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants