Coder Social home page Coder Social logo

torchkeras's People

Contributors

laugh12321 avatar lyhue1991 avatar sawyerbutton avatar zhangyu345293721 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

torchkeras's Issues

Expected all tensors to be on the same device, but found at least two devices, cuda:3 and cuda:0! (when checking argument for argument target in method wrapper_CUDA_nll_loss_forward

ๆˆ‘ๅœจๅคšgpu ่ฟ่กŒๆ‚จ็š„examples/ChatGLM2โ€”โ€”transformers.ipynb ็š„่ฎญ็ปƒ่„šๆœฌ๏ผŒๆŠฅ ๅฆ‚ไธ‹้”™่ฏฏ๏ผš
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:3 and cuda:0!
(when checking argument for argument target in method wrapper_CUDA_nll_loss_forward)
in :1 โ”‚
โ”‚ โ”‚
โ”‚ โฑ 1 keras_model.fit(train_data = dl_train, โ”‚
โ”‚ 2 โ”‚ โ”‚ โ”‚ โ”‚ val_data = dl_val, โ”‚
โ”‚ 3 โ”‚ โ”‚ โ”‚ โ”‚ epochs=100,patience=5, โ”‚
โ”‚ 4 โ”‚ โ”‚ โ”‚ โ”‚ monitor='val_loss',mode='min', โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/torchkeras/kerasmodel.py:204 in โ”‚
โ”‚ fit โ”‚
โ”‚ โ”‚
โ”‚ 201 โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ 202 โ”‚ โ”‚ โ”‚ train_epoch_runner = self.EpochRunner(train_step_runner,should_quiet) โ”‚
โ”‚ 203 โ”‚ โ”‚ โ”‚ train_metrics = {'epoch':epoch} โ”‚
โ”‚ โฑ 204 โ”‚ โ”‚ โ”‚ train_metrics.update(train_epoch_runner(train_dataloader)) โ”‚
โ”‚ 205 โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ 206 โ”‚ โ”‚ โ”‚ for name, metric in train_metrics.items(): โ”‚
โ”‚ 207 โ”‚ โ”‚ โ”‚ โ”‚ self.history[name] = self.history.get(name, []) + [metric] โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/torchkeras/kerasmodel.py:77 in โ”‚
โ”‚ call โ”‚
โ”‚ โ”‚
โ”‚ 74 โ”‚ โ”‚ โ”‚
โ”‚ 75 โ”‚ โ”‚ for step, batch in loop: โ”‚
โ”‚ 76 โ”‚ โ”‚ โ”‚ with self.accelerator.accumulate(self.net): โ”‚
โ”‚ โฑ 77 โ”‚ โ”‚ โ”‚ โ”‚ step_losses,step_metrics = self.steprunner(batch) โ”‚
โ”‚ 78 โ”‚ โ”‚ โ”‚ โ”‚ step_log = dict(step_losses,**step_metrics) โ”‚
โ”‚ 79 โ”‚ โ”‚ โ”‚ โ”‚ for k,v in step_losses.items(): โ”‚
โ”‚ 80 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ epoch_losses[k] = epoch_losses.get(k,0.0)+v โ”‚
โ”‚ โ”‚
โ”‚ in call:20 โ”‚
โ”‚ โ”‚
โ”‚ 17 โ”‚ โ”‚ โ”‚
โ”‚ 18 โ”‚ โ”‚ #loss โ”‚
โ”‚ 19 โ”‚ โ”‚ with self.accelerator.autocast(): โ”‚
โ”‚ โฑ 20 โ”‚ โ”‚ โ”‚ loss = self.net(input_ids=batch["input_ids"],labels=batch["labels"]).loss โ”‚
โ”‚ 21 โ”‚ โ”‚ โ”‚
โ”‚ 22 โ”‚ โ”‚ #backward() โ”‚
โ”‚ 23 โ”‚ โ”‚ if self.optimizer is not None and self.stage=="train": โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/torch/nn/modules/module.py:1501 โ”‚
โ”‚ in _call_impl โ”‚
โ”‚ โ”‚
โ”‚ 1498 โ”‚ โ”‚ if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks โ”‚
โ”‚ 1499 โ”‚ โ”‚ โ”‚ โ”‚ or _global_backward_pre_hooks or _global_backward_hooks โ”‚
โ”‚ 1500 โ”‚ โ”‚ โ”‚ โ”‚ or _global_forward_hooks or _global_forward_pre_hooks): โ”‚
โ”‚ โฑ 1501 โ”‚ โ”‚ โ”‚ return forward_call(*args, **kwargs) โ”‚
โ”‚ 1502 โ”‚ โ”‚ # Do not call functions when jit is used โ”‚
โ”‚ 1503 โ”‚ โ”‚ full_backward_hooks, non_full_backward_hooks = [], [] โ”‚
โ”‚ 1504 โ”‚ โ”‚ backward_pre_hooks = [] โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/accelerate/utils/operations.py:52 โ”‚
โ”‚ 1 in forward โ”‚
โ”‚ โ”‚
โ”‚ 518 โ”‚ model_forward = ConvertOutputsToFp32(model_forward) โ”‚
โ”‚ 519 โ”‚ โ”‚
โ”‚ 520 โ”‚ def forward(*args, **kwargs): โ”‚
โ”‚ โฑ 521 โ”‚ โ”‚ return model_forward(*args, **kwargs) โ”‚
โ”‚ 522 โ”‚ โ”‚
โ”‚ 523 โ”‚ # To act like a decorator so that it can be popped when doing `extract_model_from_pa โ”‚
โ”‚ 524 โ”‚ forward.wrapped = model_forward โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/accelerate/utils/operations.py:50 โ”‚
โ”‚ 9 in call โ”‚
โ”‚ โ”‚
โ”‚ 506 โ”‚ โ”‚ update_wrapper(self, model_forward) โ”‚
โ”‚ 507 โ”‚ โ”‚
โ”‚ 508 โ”‚ def call(self, *args, **kwargs): โ”‚
โ”‚ โฑ 509 โ”‚ โ”‚ return convert_to_fp32(self.model_forward(*args, **kwargs)) โ”‚
โ”‚ 510 โ”‚ โ”‚
โ”‚ 511 โ”‚ def getstate(self): โ”‚
โ”‚ 512 โ”‚ โ”‚ raise pickle.PicklingError( โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/torch/amp/autocast_mode.py:14 in โ”‚
โ”‚ decorate_autocast โ”‚
โ”‚ โ”‚
โ”‚ 11 โ”‚ @functools.wraps(func) โ”‚
โ”‚ 12 โ”‚ def decorate_autocast(*args, **kwargs): โ”‚
โ”‚ 13 โ”‚ โ”‚ with autocast_instance: โ”‚
โ”‚ โฑ 14 โ”‚ โ”‚ โ”‚ return func(*args, **kwargs) โ”‚
โ”‚ 15 โ”‚ decorate_autocast.__script_unsupported = '@autocast() decorator is not supported in โ”‚
โ”‚ 16 โ”‚ return decorate_autocast โ”‚
โ”‚ 17 โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/peft/peft_model.py:686 in forward โ”‚
โ”‚ โ”‚
โ”‚ 683 โ”‚ ): โ”‚
โ”‚ 684 โ”‚ โ”‚ peft_config = self.active_peft_config โ”‚
โ”‚ 685 โ”‚ โ”‚ if not isinstance(peft_config, PromptLearningConfig): โ”‚
โ”‚ โฑ 686 โ”‚ โ”‚ โ”‚ return self.base_model( โ”‚
โ”‚ 687 โ”‚ โ”‚ โ”‚ โ”‚ input_ids=input_ids, โ”‚
โ”‚ 688 โ”‚ โ”‚ โ”‚ โ”‚ attention_mask=attention_mask, โ”‚
โ”‚ 689 โ”‚ โ”‚ โ”‚ โ”‚ inputs_embeds=inputs_embeds, โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/torch/nn/modules/module.py:1501 โ”‚
โ”‚ in _call_impl โ”‚
โ”‚ โ”‚
โ”‚ 1498 โ”‚ โ”‚ if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks โ”‚
โ”‚ 1499 โ”‚ โ”‚ โ”‚ โ”‚ or _global_backward_pre_hooks or _global_backward_hooks โ”‚
โ”‚ 1500 โ”‚ โ”‚ โ”‚ โ”‚ or _global_forward_hooks or _global_forward_pre_hooks): โ”‚
โ”‚ โฑ 1501 โ”‚ โ”‚ โ”‚ return forward_call(*args, **kwargs) โ”‚
โ”‚ 1502 โ”‚ โ”‚ # Do not call functions when jit is used โ”‚
โ”‚ 1503 โ”‚ โ”‚ full_backward_hooks, non_full_backward_hooks = [], [] โ”‚
โ”‚ 1504 โ”‚ โ”‚ backward_pre_hooks = [] โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/accelerate/hooks.py:165 in โ”‚
โ”‚ new_forward โ”‚
โ”‚ โ”‚
โ”‚ 162 โ”‚ โ”‚ โ”‚ with torch.no_grad(): โ”‚
โ”‚ 163 โ”‚ โ”‚ โ”‚ โ”‚ output = old_forward(*args, **kwargs) โ”‚
โ”‚ 164 โ”‚ โ”‚ else: โ”‚
โ”‚ โฑ 165 โ”‚ โ”‚ โ”‚ output = old_forward(*args, **kwargs) โ”‚
โ”‚ 166 โ”‚ โ”‚ return module._hf_hook.post_forward(module, output) โ”‚
โ”‚ 167 โ”‚ โ”‚
โ”‚ 168 โ”‚ module.forward = new_forward โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/.cache/huggingface/modules/transformers_modules/THUDM/chatglm2-6b/c57e892806dfe383cd5 โ”‚
โ”‚ caf09719628788fe96379/modeling_chatglm.py:957 in forward โ”‚
โ”‚ โ”‚
โ”‚ 954 โ”‚ โ”‚ โ”‚ shift_labels = labels[..., 1:].contiguous() โ”‚
โ”‚ 955 โ”‚ โ”‚ โ”‚ # Flatten the tokens โ”‚
โ”‚ 956 โ”‚ โ”‚ โ”‚ loss_fct = CrossEntropyLoss(ignore_index=-100) โ”‚
โ”‚ โฑ 957 โ”‚ โ”‚ โ”‚ loss = loss_fct(shift_logits.view(-1, shift_logits.size(-1)), shift_labels.v โ”‚
โ”‚ 958 โ”‚ โ”‚ โ”‚ โ”‚
โ”‚ 959 โ”‚ โ”‚ โ”‚ lm_logits = lm_logits.to(hidden_states.dtype) โ”‚
โ”‚ 960 โ”‚ โ”‚ โ”‚ loss = loss.to(hidden_states.dtype) โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/torch/nn/modules/module.py:1501 โ”‚
โ”‚ in _call_impl โ”‚
โ”‚ โ”‚
โ”‚ 1498 โ”‚ โ”‚ if not (self._backward_hooks or self._backward_pre_hooks or self._forward_hooks โ”‚
โ”‚ 1499 โ”‚ โ”‚ โ”‚ โ”‚ or _global_backward_pre_hooks or _global_backward_hooks โ”‚
โ”‚ 1500 โ”‚ โ”‚ โ”‚ โ”‚ or _global_forward_hooks or _global_forward_pre_hooks): โ”‚
โ”‚ โฑ 1501 โ”‚ โ”‚ โ”‚ return forward_call(*args, **kwargs) โ”‚
โ”‚ 1502 โ”‚ โ”‚ # Do not call functions when jit is used โ”‚
โ”‚ 1503 โ”‚ โ”‚ full_backward_hooks, non_full_backward_hooks = [], [] โ”‚
โ”‚ 1504 โ”‚ โ”‚ backward_pre_hooks = [] โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/torch/nn/modules/loss.py:1174 in โ”‚
โ”‚ forward โ”‚
โ”‚ โ”‚
โ”‚ 1171 โ”‚ โ”‚ self.label_smoothing = label_smoothing โ”‚
โ”‚ 1172 โ”‚ โ”‚
โ”‚ 1173 โ”‚ def forward(self, input: Tensor, target: Tensor) -> Tensor: โ”‚
โ”‚ โฑ 1174 โ”‚ โ”‚ return F.cross_entropy(input, target, weight=self.weight, โ”‚
โ”‚ 1175 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ ignore_index=self.ignore_index, reduction=self.reduction, โ”‚
โ”‚ 1176 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ label_smoothing=self.label_smoothing) โ”‚
โ”‚ 1177 โ”‚
โ”‚ โ”‚
โ”‚ /u01/liuys/anaconda3/envs/chatglm/lib/python3.11/site-packages/torch/nn/functional.py:3029 in โ”‚
โ”‚ cross_entropy โ”‚
โ”‚ โ”‚
โ”‚ 3026 โ”‚ โ”‚ ) โ”‚
โ”‚ 3027 โ”‚ if size_average is not None or reduce is not None: โ”‚
โ”‚ 3028 โ”‚ โ”‚ reduction = _Reduction.legacy_get_string(size_average, reduce) โ”‚
โ”‚ โฑ 3029 โ”‚ return torch._C._nn.cross_entropy_loss(input, target, weight, _Reduction.get_enum(re โ”‚
โ”‚ 3030 โ”‚
โ”‚ 3031 โ”‚
โ”‚ 3032 def binary_cross_entropy(

AttributeError: partially initialized module 'torchkeras' has no attribute 'KerasModel' (most likely due to a circular import)

`from model import LeNet
import torchkeras
import torchmetrics
from torchvision import datasets
import torch.nn as nn
import torch
import torchvision.transforms as transforms
import torchvision

transform = transforms.Compose(
[transforms.ToTensor(),
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))])

batch_size = 4
net = LeNet()
model = torchkeras.KerasModel(net,
loss_fn = nn.BCEWithLogitsLoss(),
optimizer= torch.optim.Adam(net.parameters(),lr = 1e-4),
metrics_dict = {"acc":torchmetrics.Accuracy(task='binary')}
)

trainset = torchvision.datasets.CIFAR10(root='../../../../Dataset', train=True,
download=False, transform=transform)
trainloader = torch.utils.data.DataLoader(trainset, batch_size=batch_size,
shuffle=True, num_workers=2)

testset = torchvision.datasets.CIFAR10(root='../../../../Dataset', train=False,
download=False, transform=transform)
testloader = torch.utils.data.DataLoader(testset, batch_size=batch_size,
shuffle=False, num_workers=2)

dfhistory=model.fit(train_data=trainloader,
val_data=testloader,
epochs=20,
patience=3,
ckpt_path='checkpoint.pt',
monitor="val_acc",
mode="max",
plot=True,
)`

cannot import name 'LightModel' from 'torchkeras'

3.9.2็‰ˆๆœฌ็š„torchkerasไธญ่ฟ่กŒfrom torchkeras import LightModel ไผšๅ‡บ็Žฐcannot import name 'LightModel' from 'torchkeras'๏ผŒไน‹ๅ‰็‰ˆๆœฌๆ˜ฏๅฏไปฅ็š„๏ผŒๆœ€ๆ–ฐ็‰ˆLightModel่ขซๅŽป้™คไบ†ๅ—๏ผŸ

aubot multi-input model

hi, i get a problem when i use torch.summary function to print the multi-input model structure, i don't know how to pass parameters to "input_shape", i tried tuple like ((10, ), (10, 1)) and list like [(10, ), (10, )], can you help me?thanks in advance.

import torchkerasๆŠฅ้”™

ๆ็คบtorchkeras No module named 'accelerate'
pipๅฎ‰่ฃ…accelerateๅŽ
ๆ็คบAttributeError: module 'signal' has no attribute 'SIGKILL'

ๆˆ‘็š„็Žฏๅขƒๆ˜ฏwindow๏ผŒpy3.9.13๏ผŒtorchkeras3.2.5

torchkeras.LightModel can't be used!

็‰ˆๆœฌ3.8.0๏ผŒimport torchkerasๆ—ถๆ€ปๆ˜ฏๅ‡บ็Žฐ่ฟ™ไธช๏ผŒๅฆ‚ๆžœ็›ดๆŽฅimport torchkeras.LightModelไนŸไผšๆŠฅ้”™๏ผŒ็œ‹ไบ†ไธ€ไธ‹LightModelๅฎšไน‰ๅœจlightmodel.pyไธญ๏ผŒไฝ†ไธบไป€ไนˆimportไธๆˆๅŠŸๅ‘ข๏ผŸ

loss่ฎก็ฎ—ไผ ๅ…ฅๅ‚ๆ•ฐ้—ฎ้ข˜

ๆ‚จๅฅฝ๏ผŒ่‡ชๅฎšไน‰loss้œ€่ฆไผ ๅ…ฅๅ…ถไป–ๅ‚ๆ•ฐ๏ผŒไฝ†ๆ˜ฏStepRunnerไธญself.loss_fn(preds,labels)ๅชๆŽฅๅ—้ข„ๆต‹ๅ’Œๆ ‡็ญพ๏ผŒ้™คไบ†ไฟฎๆ”นๆบ็ ๅค–๏ผŒ่ฟ˜ๆœ‰ๅ…ถไป–ๆ›ดไผ˜้›…็š„ๆ–นๆณ•ๅ—

ๆณจๅ†Œchatglm้ญ”ๆณ•ๅ‘ฝไปคๅ‡บ้”™

# ้€š่ฟ‡ๆณจๅ†Œjupyter้ญ”ๆณ•ๅ‘ฝไปคๅฏไปฅๅพˆๆ–นไพฟๅœฐๅœจjupyterไธญๆต‹่ฏ•ChatGLM 
from torchkeras.chat import ChatGLM 
chatglm = ChatGLM(model, tokenizer)
register magic %%chatglm sucessed ...
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[5], line 3
      1 # ้€š่ฟ‡ๆณจๅ†Œjupyter้ญ”ๆณ•ๅ‘ฝไปคๅฏไปฅๅพˆๆ–นไพฟๅœฐๅœจjupyterไธญๆต‹่ฏ•ChatGLM 
      2 from torchkeras.chat import ChatGLM 
----> 3 chatglm = ChatGLM(model, tokenizer)

File ~/anaconda3/envs/zdw/lib/python3.10/site-packages/torchkeras/chat/chatglm.py:27, in ChatGLM.__init__(self, model, tokenizer, stream, max_chat_rounds, history, max_length, num_beams, do_sample, top_p, temperature, logits_processor)
     24     print('register magic %%chatglm failed ...')
     25     print(err)
---> 27 response = self('ไฝ ๅฅฝ')
     28 if not self.stream:
     29     print(response)

File ~/anaconda3/envs/zdw/lib/python3.10/site-packages/torchkeras/chat/chatglm.py:50, in ChatGLM.__call__(self, query)
     43     return response 
     45 result = self.model.stream_chat(self.tokenizer,
     46     query,self.history,None,self.max_length,
     47     self.do_sample,self.top_p,self.temperature,
     48     self.logits_processor,None)
---> 50 for response,history in result:
     51     print(response)
     52     clear_output(wait=True)

File ~/anaconda3/envs/zdw/lib/python3.10/site-packages/torch/utils/_contextlib.py:26, in _wrap_generator.<locals>.generator_context(*args, **kwargs)
     24 @functools.wraps(func)
     25 def generator_context(*args, **kwargs):
---> 26     gen = func(*args, **kwargs)
     28     # Generators are suspended and unsuspended at `yield`, hence we
     29     # make sure the grad mode is properly set every time the execution
     30     # flow returns into the wrapped generator and restored when it
     31     # returns through our `yield` to our caller (see PR #49017).
     32     try:
     33         # Issuing `None` to a generator fires it up

TypeError: ChatGLMForConditionalGeneration.stream_chat() takes from 3 to 9 positional arguments but 11 were given

่ฏท้—ฎๆ˜ฏๅ“ช้‡Œๅ‡บ้—ฎ้ข˜ไบ†ๅ•Š

I think the `torchkeras.torchkeras.Model.forward()` function needs to be slightly modified.

When I'm using a multi-input model (such as aTransformer model), I get errors like TypeError: forward() missing 2 required positional arguments: 'tgt' and 'tgt_mask'.
I looked at the source code of torchkeras and thought that there was a problem with the way the parameters of the torchkeras.torchkeras.Model.forward() function were passed.

So I suggest modifying the torchkeras.torchkeras.Model.forward() function like this:

Change:

def forward(self, x):
if self.net:
return self.net.forward(x)
else:
raise NotImplementedError

To:

    def forward(self, *x):  #Attention this line 
        if self.net:
            return self.net.forward(*x)  #Attention this line 
        else:
            raise NotImplementedError

Also, the place where the torchkeras.torchkeras.Model.forward() function is used should also be modified, as follows:

Change:

predictions = self.forward(features)

To:

        predictions = self.forward(*features)

and many more.

If my suggestion is wrong, please ignore my suggestion.

ๅฏนๅญฆไน ็Ž‡่กฐๅ‡ๆ”ฏๆŒๅพ—ไธๅฅฝ

้ฆ–ๅ…ˆๆ„Ÿ่ฐขๅผ€ๆบ่ฟ™ไนˆๆœ‰ๆ„ไน‰็š„้กน็›ฎ๏ผ

ๅ‘็Žฐtorchkerasๅฏนๅฏนๅญฆไน ็Ž‡่กฐๅ‡ๆ”ฏๆŒๅพ—ไธๅฅฝ๏ผŒ้ฆ–ๅ…ˆๆ˜ฏlr_scheduler.step()ๆฒกไผ ๅ…ฅๅ‚ๆ•ฐmetrics๏ผŒๅ…ถๆฌกๆ˜ฏไฝฟ็”จlr_schedulerๅŽ๏ผŒๅญฆไน ็Ž‡ๆ˜Žๆ˜Žๅทฒ็ปไธ‹้™๏ผŒไฝ†processing barๆ˜พ็คบ็š„lrไป็„ถไธๅ˜โ€ฆโ€ฆ ๆ”น่ตทๆฅๅบ”่ฏฅไธ้šพ๏ผŒๅธŒๆœ›ไฝœ่€…ๆ›ดๆ–ฐfix

PicklingError: Cannot pickle a prepared model with automatic mixed precision, please unwrap the model with `Accelerator.unwrap_model(model)` before pickling it.

================================================================================2023-07-06 14:03:03
Epoch 1 / 100

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ Traceback (most recent call last) โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ /torchkeras/train.py:230 in โ”‚
โ”‚ โ”‚
โ”‚ 227 โ”‚ โ”‚ optimizer=torch.optim.AdamW(model.parameters(),lr=2e-6)) โ”‚
โ”‚ 228 ckpt_path = './waimai_chatglm4' โ”‚
โ”‚ 229 โ”‚
โ”‚ โฑ 230 keras_model.fit(train_data = dl_train, โ”‚
โ”‚ 231 โ”‚ โ”‚ โ”‚ โ”‚ val_data = dl_val, โ”‚
โ”‚ 232 โ”‚ โ”‚ โ”‚ โ”‚ epochs=100,patience=5, โ”‚
โ”‚ 233 โ”‚ โ”‚ โ”‚ โ”‚ monitor='val_loss',mode='min', โ”‚
โ”‚ โ”‚
โ”‚ /torchkeras/torchkeras/kerasmodel.py:204 in fit โ”‚
โ”‚ โ”‚
โ”‚ 201 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ loss_fn = self.loss_fn, โ”‚
โ”‚ 202 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ accelerator = self.accelerator, โ”‚
โ”‚ 203 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ stage="train", โ”‚
โ”‚ โฑ 204 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ metrics_dict=deepcopy(self.metrics_dict), โ”‚
โ”‚ 205 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ optimizer = self.optimizer if epoch>0 else None, โ”‚
โ”‚ 206 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ lr_scheduler = self.lr_scheduler if epoch>0 else None โ”‚
โ”‚ 207 โ”‚ โ”‚ โ”‚ ) โ”‚
โ”‚ โ”‚
โ”‚ /usr/lib/python3.8/copy.py:172 in deepcopy โ”‚
โ”‚ โ”‚
โ”‚ 169 โ”‚ โ”‚ โ”‚ โ”‚ if isinstance(rv, str): โ”‚
โ”‚ 170 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ y = x โ”‚
โ”‚ 171 โ”‚ โ”‚ โ”‚ โ”‚ else: โ”‚
โ”‚ โฑ 172 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ y = _reconstruct(x, memo, *rv) โ”‚
โ”‚ 173 โ”‚ โ”‚
โ”‚ 174 โ”‚ # If is its own copy, don't memoize. โ”‚
โ”‚ 175 โ”‚ if y is not x: โ”‚
โ”‚ โ”‚
โ”‚ /usr/lib/python3.8/copy.py:270 in _reconstruct โ”‚
โ”‚ โ”‚
โ”‚ 267 โ”‚ โ”‚
โ”‚ 268 โ”‚ if state is not None: โ”‚
โ”‚ 269 โ”‚ โ”‚ if deep: โ”‚
โ”‚ โฑ 270 โ”‚ โ”‚ โ”‚ state = deepcopy(state, memo) โ”‚
โ”‚ 271 โ”‚ โ”‚ if hasattr(y, 'setstate'): โ”‚
โ”‚ 272 โ”‚ โ”‚ โ”‚ y.setstate(state) โ”‚
โ”‚ 273 โ”‚ โ”‚ else: โ”‚
โ”‚ โ”‚
โ”‚ /usr/lib/python3.8/copy.py:146 in deepcopy โ”‚
โ”‚ โ”‚
โ”‚ 143 โ”‚ โ”‚
โ”‚ 144 โ”‚ copier = _deepcopy_dispatch.get(cls) โ”‚
โ”‚ 145 โ”‚ if copier is not None: โ”‚
โ”‚ โฑ 146 โ”‚ โ”‚ y = copier(x, memo) โ”‚
โ”‚ 147 โ”‚ else: โ”‚
โ”‚ 148 โ”‚ โ”‚ if issubclass(cls, type): โ”‚
โ”‚ 149 โ”‚ โ”‚ โ”‚ y = _deepcopy_atomic(x, memo) โ”‚
โ”‚ โ”‚
โ”‚ /usr/lib/python3.8/copy.py:230 in _deepcopy_dict โ”‚
โ”‚ โ”‚
โ”‚ 227 โ”‚ y = {} โ”‚
โ”‚ 228 โ”‚ memo[id(x)] = y โ”‚
โ”‚ 229 โ”‚ for key, value in x.items(): โ”‚
โ”‚ โฑ 230 โ”‚ โ”‚ y[deepcopy(key, memo)] = deepcopy(value, memo) โ”‚
โ”‚ 231 โ”‚ return y โ”‚
โ”‚ 232 d[dict] = _deepcopy_dict โ”‚
โ”‚ 233 if PyStringMap is not None: โ”‚
โ”‚ โ”‚
โ”‚ /usr/lib/python3.8/copy.py:161 in deepcopy โ”‚
โ”‚ โ”‚
โ”‚ 158 โ”‚ โ”‚ โ”‚ โ”‚ else: โ”‚
โ”‚ 159 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ reductor = getattr(x, "reduce_ex", None) โ”‚
โ”‚ 160 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ if reductor is not None: โ”‚
โ”‚ โฑ 161 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ rv = reductor(4) โ”‚
โ”‚ 162 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ else: โ”‚
โ”‚ 163 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ reductor = getattr(x, "reduce", None) โ”‚
โ”‚ 164 โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ โ”‚ if reductor: โ”‚
โ”‚ โ”‚
โ”‚ /usr/local/lib/python3.8/dist-packages/accelerate/utils/operations.py:498 in getstate โ”‚
โ”‚ โ”‚
โ”‚ 495 โ”‚ โ”‚ return convert_to_fp32(self.model_forward(*args, **kwargs)) โ”‚
โ”‚ 496 โ”‚ โ”‚
โ”‚ 497 โ”‚ def getstate(self): โ”‚
โ”‚ โฑ 498 โ”‚ โ”‚ raise pickle.PicklingError( โ”‚
โ”‚ 499 โ”‚ โ”‚ โ”‚ "Cannot pickle a prepared model with automatic mixed precision, please unwra โ”‚
โ”‚ 500 โ”‚ โ”‚ ) โ”‚
โ”‚ 501 โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
PicklingError: Cannot pickle a prepared model with automatic mixed precision, please unwrap the model with Accelerator.unwrap_model(model) before pickling it.

ๅฝ“ๆˆ‘ๅผ€ๅง‹่ฎญ็ปƒ็š„ๆ—ถๅ€™ๆŠฅ่ฟ™ไธช้”™่ฏฏ๏ผŒ่ƒฝๅธฎๅฟ™่งฃๅ†ณๅ—๏ผŸ

BaiChuan13B_NERโ€”โ€”transformersๆจกๅž‹ๅพฎ่ฐƒๅŽ็ป“ๆžœๅ˜ๅฐ

ๆ‚จๅฅฝ๏ผŒๅคงไฝฌใ€‚
BaiChuan13B_NERโ€”โ€”transformersๆจกๅž‹ๅพฎ่ฐƒๆŒ‰็…งๆ‚จ็š„ๆ–‡ไปถ่ฟ่กŒไบ†ไธ€้ๆœ€ๅŽ่ท‘ๅ‡บๆฅ็š„็ป“ๆžœๅ˜ๅฐ๏ผŒๆฒกๆœ‰ๆ›ดๆ”น่ฟ‡ๆ–‡ไปถ๏ผŒ่ฟ™ๆ˜ฏๅฆๆ˜ฏ้œ€่ฆๅขžๅŠ ่ฝฎๆฌกๆˆ–่€…ๆ€Žไนˆๅค„็†ๅ‘ข๏ผŸๅ’Œๆ‚จ็š„็ป“ๆžœๅฏนไธไธŠ
image
่ท‘ๅ‡บๆฅ็š„็ป“ๆžœ๏ผš
image

model.enable_input_require_grads() ๆŠฅ้”™

1
image

่ฟ™ไธชๅฎƒๆฒกๆŠฅ้”™่ฏฏๅŽŸๅ› ๏ผŒ็œ‹ไธๅ‡บๆฅๅ’‹ๅ›žไบ‹๏ผŒๅคงไฝฌๅฏไปฅๅๅŠฉ่งฃๅ†ณๅ˜›๏ผŸ

ๆ€Žไนˆไฝฟ็”จmpsๆฅ่ฟ›่กŒ่ฎญ็ปƒ

ๆˆ‘็œ‹ๆ•™็จ‹ๅฅฝๅƒๆ˜ฏ่‡ชๅŠจ้€‰ๆ‹ฉ็š„๏ผŒไฝ†ๆ˜ฏๆˆ‘ๅฎž้™…ไฝฟ็”จไธญ๏ผŒ่ฟ˜ๆ˜ฏๆ˜พ็คบ็š„cpu๏ผŒtorchkeras็‰ˆๆœฌๅทฒ็ปๆ›ดๆ–ฐๅˆฐๆœ€ๆ–ฐ

ไฟๅญ˜ๆจกๅž‹ๅŽ่ฐƒ็”จๆŠฅ้”™ clean_up_tokenization_spaces ๆ˜พ็คบ็ฑปๅž‹้”™่ฏฏ๏ผŒๆ„Ÿ่ง‰ไธๅบ”่ฏฅ

TypeError: transformers.tokenization_utils.PreTrainedTokenizer.init() got multiple values for keyword argument 'clean_up_tokenization_spaces'

TypeError Traceback (most recent call last)
Cell In[13], line 3
1 from transformers import AutoModel,AutoTokenizer
2 model_name = "/mnt/workspace/chatglm2-6b-AdaLoRA/chatglm2-6b-ๆขฆไธญๆƒ…็‚‰"
----> 3 tokenizer = AutoTokenizer.from_pretrained(
4 model_name, trust_remote_code=True)
5 model = AutoModel.from_pretrained(model_name,
6 trust_remote_code=True).half().cuda()

File /home/pai/lib/python3.9/site-packages/transformers/models/auto/tokenization_auto.py:679, in AutoTokenizer.from_pretrained(cls, pretrained_model_name_or_path, *inputs, **kwargs)
675 if tokenizer_class is None:
676 raise ValueError(
677 f"Tokenizer class {tokenizer_class_candidate} does not exist or is not currently imported."
678 )
--> 679 return tokenizer_class.from_pretrained(pretrained_model_name_or_path, *inputs, **kwargs)
681 # Otherwise we have to be creative.
682 # if model is an encoder decoder, the encoder tokenizer class is used by default
683 if isinstance(config, EncoderDecoderConfig):

File /home/pai/lib/python3.9/site-packages/transformers/tokenization_utils_base.py:1804, in PreTrainedTokenizerBase.from_pretrained(cls, pretrained_model_name_or_path, *init_inputs, **kwargs)
1801 else:
1802 logger.info(f"loading file {file_path} from cache at {resolved_vocab_files[file_id]}")
-> 1804 return cls._from_pretrained(
1805 resolved_vocab_files,
1806 pretrained_model_name_or_path,
1807 init_configuration,
1808 *init_inputs,
1809 use_auth_token=use_auth_token,
1810 cache_dir=cache_dir,
1811 local_files_only=local_files_only,
1812 _commit_hash=commit_hash,
1813 **kwargs,
1814 )

File /home/pai/lib/python3.9/site-packages/transformers/tokenization_utils_base.py:1958, in PreTrainedTokenizerBase._from_pretrained(cls, resolved_vocab_files, pretrained_model_name_or_path, init_configuration, use_auth_token, cache_dir, local_files_only, _commit_hash, *init_inputs, **kwargs)
1956 # Instantiate tokenizer.
1957 try:
-> 1958 tokenizer = cls(*init_inputs, **init_kwargs)
1959 except OSError:
1960 raise OSError(
1961 "Unable to load vocabulary from file. "
1962 "Please check that the provided vocabulary is accessible and not corrupted."
1963 )

File ~/.cache/huggingface/modules/transformers_modules/chatglm2-6b-ๆขฆไธญๆƒ…็‚‰/tokenization_chatglm.py:69, in ChatGLMTokenizer.init(self, vocab_file, padding_side, **kwargs)
68 def init(self, vocab_file, padding_side="left", **kwargs):
---> 69 super().init(padding_side=padding_side, clean_up_tokenization_spaces=False, **kwargs)
70 self.name = "GLMTokenizer"
72 self.vocab_file = vocab_file

TypeError: transformers.tokenization_utils.PreTrainedTokenizer.init() got multiple values for keyword argument 'clean_up_tokenization_spaces'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.