Comments (5)
以下是修改后跑通deepspeed单机多卡的主要替换代码(替换 trainer=LoRATrainer 及之后的部分):
model_engine, optimizer, train_dataloader, _ = deepspeed.initialize(config=conf,
model=model,
model_parameters=model.parameters(),
training_data=train_dataset,
collate_fn=coll_fn)
model_engine.train()
for i_epoch in range(global_args.num_train_epochs):
for micro_step, batch in enumerate(train_dataloader):
input_ids = batch["input_ids"].to(model_engine.local_rank)
labels = batch["labels"].to(model_engine.local_rank)
outputs = model_engine.forward(input_ids=input_ids, labels=labels)
loss = outputs[0]
model_engine.backward(loss)
model_engine.step()
save_dir = f'{global_args.output_dir}/{i_epoch}'
model_engine.save_pretrained(save_dir)
补充:
- 这里coll_fn用原始的DataCollatorForChatGLM会有问题,coll_fn是一个单独的函数(类似DataCollatorForChatGLM.call)
- model加载时复用了官方脚本里的加载方式
最后train.sh里的python改成deepspeed启动就可以了
from chatglm-6b-qlora.
暂时还有点问题,我也在调试,会尽快更新
from chatglm-6b-qlora.
以下是修改后跑通deepspeed单机多卡的主要替换代码(替换 trainer=LoRATrainer 及之后的部分):
model_engine, optimizer, train_dataloader, _ = deepspeed.initialize(config=conf, model=model, model_parameters=model.parameters(), training_data=train_dataset, collate_fn=coll_fn) model_engine.train() for i_epoch in range(global_args.num_train_epochs): for micro_step, batch in enumerate(train_dataloader): input_ids = batch["input_ids"].to(model_engine.local_rank) labels = batch["labels"].to(model_engine.local_rank) outputs = model_engine.forward(input_ids=input_ids, labels=labels) loss = outputs[0] model_engine.backward(loss) model_engine.step() save_dir = f'{global_args.output_dir}/{i_epoch}' model_engine.save_pretrained(save_dir)
补充:
- 这里coll_fn用原始的DataCollatorForChatGLM会有问题,coll_fn是一个单独的函数(类似DataCollatorForChatGLM.call)
- model加载时复用了官方脚本里的加载方式
最后train.sh里的python改成deepspeed启动就可以了
这个conf是lora_config吗
不是,conf是deepspeed的配置,比如像下面这样
conf = {"train_micro_batch_size_per_gpu": args.per_device_train_batch_size,
"gradient_accumulation_steps": args.gradient_accumulation_steps,
"gradient_clipping": 1.0,
"optimizer": {
"type": "Adam",
"params": {
"lr": args.learning_rate,
"betas": [
0.9,
0.95
],
"eps": 1e-8,
"weight_decay": args.weight_decay
}
},
"fp16": {
"enabled": False
},
"zero_optimization": {
"stage": args.zero_stage,
"offload_optimizer": {
"device": "cpu",
"pin_memory": True
},
"allgather_partitions": True,
"allgather_bucket_size": 2e8,
"overlap_comm": True,
"reduce_scatter": True,
"reduce_bucket_size": 2e8,
"contiguous_gradients": True
},
}
from chatglm-6b-qlora.
以下是修改后跑通deepspeed单机多卡的主要替换代码(替换 trainer=LoRATrainer 及之后的部分):
model_engine, optimizer, train_dataloader, _ = deepspeed.initialize(config=conf, model=model, model_parameters=model.parameters(), training_data=train_dataset, collate_fn=coll_fn) model_engine.train() for i_epoch in range(global_args.num_train_epochs): for micro_step, batch in enumerate(train_dataloader): input_ids = batch["input_ids"].to(model_engine.local_rank) labels = batch["labels"].to(model_engine.local_rank) outputs = model_engine.forward(input_ids=input_ids, labels=labels) loss = outputs[0] model_engine.backward(loss) model_engine.step() save_dir = f'{global_args.output_dir}/{i_epoch}' model_engine.save_pretrained(save_dir)
补充:
- 这里coll_fn用原始的DataCollatorForChatGLM会有问题,coll_fn是一个单独的函数(类似DataCollatorForChatGLM.call)
- model加载时复用了官方脚本里的加载方式
最后train.sh里的python改成deepspeed启动就可以了
多卡训练会报错,untimeError: Expected all tensors to be on the same device, but found at least two devices,你有遇到吗
from chatglm-6b-qlora.
以下是修改后跑通deepspeed单机多卡的主要替换代码(替换 trainer=LoRATrainer 及之后的部分):
model_engine, optimizer, train_dataloader, _ = deepspeed.initialize(config=conf, model=model, model_parameters=model.parameters(), training_data=train_dataset, collate_fn=coll_fn) model_engine.train() for i_epoch in range(global_args.num_train_epochs): for micro_step, batch in enumerate(train_dataloader): input_ids = batch["input_ids"].to(model_engine.local_rank) labels = batch["labels"].to(model_engine.local_rank) outputs = model_engine.forward(input_ids=input_ids, labels=labels) loss = outputs[0] model_engine.backward(loss) model_engine.step() save_dir = f'{global_args.output_dir}/{i_epoch}' model_engine.save_pretrained(save_dir)
补充:
- 这里coll_fn用原始的DataCollatorForChatGLM会有问题,coll_fn是一个单独的函数(类似DataCollatorForChatGLM.call)
- model加载时复用了官方脚本里的加载方式
最后train.sh里的python改成deepspeed启动就可以了
多卡训练会报错,untimeError: Expected all tensors to be on the same device, but found at least two devices,你有遇到吗
我遇到的时候这个报错是来自于model加载部分,也就是在这块代码之前model=xxxModel()那里,或许可以看一下model_device_map是不是正确的
from chatglm-6b-qlora.
Related Issues (20)
- 数据集格式instruction,input,output时tokenized出错 HOT 2
- 训练结束后,数据展示出现问题
- merge后模型Loading checkpoint shards Killed HOT 6
- 调优后的模型是否可以在CPU服务上部署? HOT 1
- protobuf 和 icetk 版本不兼容 HOT 1
- ImportError: libcudnn.so.8: cannot open shared object file: No such file or directory HOT 12
- RuntimeError: mat1 and mat2 shapes cannot be multiplied (588x4096 and 1x9437184) ,ChatGLM2-6B做微调,请问如何设置参数?? HOT 1
- RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:1 and cuda:0! (when checking argument for argument target in method wrapper_CUDA_nll_loss_forward),请问如何调整训练代码,适配多卡训练?? HOT 1
- transformers>4.30.2时,模型不会进行量化,是因为什么?
- BrokenPipeError: [Errno 32] Broken pipe HOT 7
- 训练结束后没有保存完整的adapter文件 HOT 2
- 用V100显卡微调chatglm2-6b,但是loss一直为0,eval_loss=nan
- 训练显存有些问题
- 微调后推理性能问题 HOT 1
- ChatGLM3-6B 微调报错 RuntimeError: CUDA error: invalid argument HOT 1
- ChatGLM2-6B微调后合并报错We need an `offload_dir` to dispatch this model according to this `device_map`, the following submodules need to be offloaded: HOT 2
- 合并模型的时候显存不够,用的4090,24G
- qlora微调训练随机性
- ValueError:
- ChatGLM2-6b模型合并时报错ValueError: We need an `offload_dir` to dispatch this model according to this `device_map`, the following submodules need to be offloaded
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chatglm-6b-qlora.