当前位置: 首页 > news >正文

Deepspeed : AttributeError: ‘DummyOptim‘ object has no attribute ‘step‘

题意:尝试在一个名为 DummyOptim 的对象上调用 .step() 方法,但是这个对象并没有定义这个方法

问题背景:

I want to use deepspeed for training LLMs along with Huggingface Trainer. But when I use deepspeed along with trainer I get error "AttributeError: 'DummyOptim' object has no attribute 'step'". Below is my code

尝试结合使用 DeepSpeed 和 Hugging Face 的 Trainer API 来训练大型语言模型(LLMs)时遇到 "AttributeError: 'DummyOptim' object has no attribute 'step'" 这个错误,下面是我的代码:

import argparse
import numpy as np
import torch
from datasets import load_dataset
from transformers import AutoTokenizer, AutoModelForCausalLMfrom trl import DPOTrainer, DPOConfig
def preprocess_data(item):return {'prompt': 'Instruct: ' + item['prompt'] + '\n','chosen': 'Output: ' + item['chosen'],'rejected': 'Output: ' + item['rejected']}        def main():parser = argparse.ArgumentParser()parser.add_argument("--epochs", type=int, default=1)parser.add_argument("--beta", type=float, default=0.1)parser.add_argument("--batch_size", type=int, default=4)parser.add_argument("--lr", type=float, default=1e-6)parser.add_argument("--seed", type=int, default=2003)parser.add_argument("--model_name", type=str, default="EleutherAI/pythia-14m")parser.add_argument("--dataset_name", type=str, default="jondurbin/truthy-dpo-v0.1")parser.add_argument("--local_rank", type=int, default=0)args = parser.parse_args()# Determine device based on local_rankdevice = torch.device("cuda", args.local_rank) if torch.cuda.is_available() else torch.device("cpu")tokenizer = AutoTokenizer.from_pretrained(args.model_name)tokenizer.pad_token = tokenizer.eos_tokenmodel = AutoModelForCausalLM.from_pretrained(args.model_name).to(device)ref_model = AutoModelForCausalLM.from_pretrained(args.model_name).to(device)dataset = load_dataset(args.dataset_name, split="train")dataset = dataset.map(preprocess_data)# Split the dataset into training and validation setsdataset = dataset.train_test_split(test_size=0.1, seed=args.seed)train_dataset = dataset['train']val_dataset = dataset['test']training_args = DPOConfig(learning_rate=args.lr,num_train_epochs=args.epochs,per_device_train_batch_size=args.batch_size,logging_steps=10,remove_unused_columns=False,max_length=1024,max_prompt_length=512,deepspeed="ds_config.json"       )# Verify and print embedding dimensions before finetuningprint("Base model embedding dimension:", model.config.hidden_size)model.train()ref_model.eval()dpo_trainer = DPOTrainer(model,ref_model,beta=args.beta,train_dataset=train_dataset,eval_dataset=val_dataset,tokenizer=tokenizer,args=training_args,)dpo_trainer.train()# Evaluateevaluation_results = dpo_trainer.evaluate()print("Evaluation Results:", evaluation_results)save_model_name = 'finetuned_model'model.save_pretrained(save_model_name)if __name__ == "__main__":main()

The config file used is the below one        使用的配置文件是下面的这个:

{
"zero_optimization": {"stage": 3,"offload_optimizer": {"device": "cpu","pin_memory": true},"offload_param": {"device": "cpu","pin_memory": true},"overlap_comm": true,"contiguous_gradients": true,"sub_group_size": 1e9,"reduce_bucket_size": "auto","stage3_prefetch_bucket_size": "auto","stage3_param_persistence_threshold": "auto","stage3_max_live_parameters": 1e9,"stage3_max_reuse_distance": 1e9,"stage3_gather_16bit_weights_on_model_save": true},
"bf16": {"enabled": "auto"
},
"fp16": {"enabled": "auto","loss_scale": 0,"initial_scale_power": 32,"loss_scale_window": 1000,"hysteresis": 2,"min_loss_scale": 1
},"gradient_accumulation_steps": "auto",
"gradient_clipping": "auto",
"train_batch_size": "auto",
"train_micro_batch_size_per_gpu": "auto",
"wall_clock_breakdown": false,
"flops_profiler": {"enabled": false,"detailed": false
},
"optimizer": {"type": "Lamb","params": {"lr": "auto","betas": [0.9, 0.999],"eps": "auto","weight_decay": "auto"}
},
"zero_allow_untested_optimizer": true
}

The code works with out deepspeed. I have torch=2.3.1, deepspeed =0.14.5, trl=0.9.4 and CUDA Version: 12.5.

在没有使用 DeepSpeed 的情况下,代码可以正常工作。当前的软件版本配置为:PyTorch 2.3.1,DeepSpeed 0.14.5,TRL 0.9.4,以及 CUDA 版本 12.5。

Appreciate any hint on this !        非常感谢您在这方面的任何提示!

问题解决:

from accelerate.utils import DistributedTypetraining_args.distributed_state.distributed_type = DistributedType.DEEPSPEED

adding this solves the issue        添加这个解决了问题

相关文章:

Deepspeed : AttributeError: ‘DummyOptim‘ object has no attribute ‘step‘

题意:尝试在一个名为 DummyOptim 的对象上调用 .step() 方法,但是这个对象并没有定义这个方法 问题背景: I want to use deepspeed for training LLMs along with Huggingface Trainer. But when I use deepspeed along with trainer I get …...

【Python123题库】#查询省会 #字典的属性、方法与应用

禁止转载,原文:https://blog.csdn.net/qq_45801887/article/details/140081665 参考教程:B站视频讲解——https://space.bilibili.com/3546616042621301 有帮助麻烦点个赞 ~ ~ Python123题库 查询省会字典的属性、方法与应用 查询省会 类型…...

数据建设实践之大数据平台(一)

大数据组件版本信息 zookeeper-3.5.7hadoop-3.3.5mysql-5.7.28apache-hive-3.1.3spark-3.3.1dataxapache-dolphinscheduler-3.1.9大数据技术架构 大数据组件部署规划 node101node102node103node104node105datax datax datax ZK ZK ZK RM RM NM...

【MIT 6.5840/6.824】Lab1 MapReduce

MapReduce MapReduce思想实现思路感受 6.5840/6.824 Lab与笔记汇总 本文对应的Lab版本为MIT6.5840-Spring2024的Lab1 本博客只提供思路,不会公开任何代码 本lab耗时约6h,码量约500行 MapReduce思想 MapReduce的思想属于是比较简单的,分为两…...

如何在 C 语言中进行选择排序?

🍅关注博主🎗️ 带你畅游技术世界,不错过每一次成长机会! 📙C 语言百万年薪修炼课程 通俗易懂,深入浅出,匠心打磨,死磕细节,6年迭代,看过的人都说好。 文章目…...

开源浏览器引擎对比与适用场景:WebKit、Chrome、Gecko

WebKit与Chrome的Blink引擎对比 起源与关系: WebKit最初由苹果公司开发,用于Safari浏览器。后来,WebKit逐渐成为一个独立的开源项目,被多个浏览器厂商采用。Blink是Google基于WebKit项目分支出来的一个浏览器引擎,用于…...

DNF客户端使用

客户端使用 1、下载客户端2、配置网关连接到服务器2.1 网关设置参数:2.2 点击连接网关2.3 点击“参数设置内容立即生效” 3、使用网关生成登陆器3.1 登陆器参数设置3.2 点击增加3.3 复制网关的通信密钥,点击生成登陆器 4、复制替换相关文件4.1 复制登陆器到客户端文…...

打包时提示:Missing Gradle Project Information.或者在加载gradle时出错

1.Android打包弹出错误提示框:missing gradle project information. please check if the IDE successfully synchronized its state with the Gradble project model. 2.加载gradle出错:修复报错后 File -> Sync Project with Gradle Files...

基于前馈神经网络 FNN 实现股票单变量时间序列预测(PyTorch版)

前言 系列专栏:【深度学习:算法项目实战】✨︎ 涉及医疗健康、财经金融、商业零售、食品饮料、运动健身、交通运输、环境科学、社交媒体以及文本和图像处理等诸多领域,讨论了各种复杂的深度神经网络思想,如卷积神经网络、循环神经网络、生成对…...

Scikit Learn - 建模手册(02)--- 数据表示、估算器

Scikit Learn - 数据表示 文章目录 一、说明二、数据表格2.1 数据作为特征矩阵2.2 数据作为目标数组 三、什么是 Estimator API四、Estimator API 的使用五、指导原则六、使用 Estimator API 的步骤七、监督学习示例八、无监督学习示例 一、说明 众所周知,机器学习…...

【鸿蒙学习笔记】通过用户首选项实现数据持久化

官方文档:通过用户首选项实现数据持久化 目录标题 使用场景第1步:源码第2步:启动模拟器第3步:启动entry第6步:操作样例2 使用场景 Preferences会将该数据缓存在内存中,当用户读取的时候,能够快…...

LabVIEW航空发动机试验器数据监测分析

1. 概述 为了适应航空发动机试验器的智能化发展,本文基于图形化编程工具LabVIEW为平台,结合航空发动机试验器原有的软硬件设备,设计开发了一套数据监测分析功能模块。主要阐述了数据监测分析功能设计中的设计思路和主要功能,以及…...

快速上手:前后端分离开发(Vue+Element+Spring Boot+MyBatis+MySQL)

文章目录 前言项目简介环境准备第一步:初始化前端项目登录页面任务管理页面 第二步:初始化后端项目数据库配置数据库表结构实体类和Mapper服务层和控制器 第三步:连接前后端总结 🎉欢迎来到架构设计专栏~探索Java中的静态变量与实…...

产品推荐| 长江存储eMMC嵌入式储存 YMTC EC230

产品详情 EC230是基于长江存储晶栈Xtacking3.0三维闪存架构打造的新一代eMMC 5.1嵌入式存储产品。EC230的最大顺序读取速度达330MB/s,支持动态SLC缓存,为终端设备提供稳定高性能;支持自动后台/自动节能等操作,减少设备延迟&#…...

【Linux】IP地址与主机名

文章目录 1.IP地址2.特殊IP地址3.主机名4.域名解析 1.IP地址 每一台联网的电脑都会有一个地址,用于和其它计算机进行通讯 IP地址主要有2个版本,V4版本和V6版本 IPv4版本的地址格式是:a.b.c.d,其中abcd表示0~255的数字,如192.168.…...

ros2--colcon

colcon ros2的编译工具,用于编译ros2项目; 需要在工作空间,也就是src上一级目录colcon build; 很明显colcon作为构建工具,通过调用CMake、Python setuptools完成构建。 小鱼文档 构建参数 --packages-select 仅构…...

PyCharm 2023.3.2 关闭时一直显示正在关闭项目

文章目录 一、问题描述二、问题原因三、解决方法 一、问题描述 PyCharm 2023.3.2 关闭时一直显示正在关闭项目 二、问题原因 因为PyCharm还没有加载完索引导致的 三、解决方法 方法一: 先使用任务管理器强制关闭,下次关闭时注意要等待PyCharm加载完索…...

VS2022 git拉取/推送代码错误

第一步:打开VS2022 第二步:工具->选项->源代码管理->Git 全局设置 第三步:加密网络提供程序设置为:OpenSSL 完结:...

【Vue】vue3中使用swipe竖直方向上滚动

安装 npm install swipe使用 import swiper/css; import swiper/css/mousewheel; import { Swiper, SwiperSlide } from swiper/vue; import { Mousewheel } from swiper/modules;containerHeight 是容器的高度,一定要设置竖直方向上滚动高度,不然会非…...

搭建基于 ChatGPT 的问答系统

搭建基于 ChatGPT 的问答系统 📣1.简介📣2.模型,范式和 token📣3.检查输入-分类📣4.检查输入-监督📣5.思维链推理📣6.提示链📣7.检查输入📣8.评估(端到端系统…...

376. Wiggle Subsequence

376. Wiggle Subsequence 代码 class Solution { public:int wiggleMaxLength(vector<int>& nums) {int n nums.size();int res 1;int prediff 0;int curdiff 0;for(int i 0;i < n-1;i){curdiff nums[i1] - nums[i];if( (prediff > 0 && curdif…...

智能在线客服平台:数字化时代企业连接用户的 AI 中枢

随着互联网技术的飞速发展&#xff0c;消费者期望能够随时随地与企业进行交流。在线客服平台作为连接企业与客户的重要桥梁&#xff0c;不仅优化了客户体验&#xff0c;还提升了企业的服务效率和市场竞争力。本文将探讨在线客服平台的重要性、技术进展、实际应用&#xff0c;并…...

【项目实战】通过多模态+LangGraph实现PPT生成助手

PPT自动生成系统 基于LangGraph的PPT自动生成系统&#xff0c;可以将Markdown文档自动转换为PPT演示文稿。 功能特点 Markdown解析&#xff1a;自动解析Markdown文档结构PPT模板分析&#xff1a;分析PPT模板的布局和风格智能布局决策&#xff1a;匹配内容与合适的PPT布局自动…...

JVM暂停(Stop-The-World,STW)的原因分类及对应排查方案

JVM暂停(Stop-The-World,STW)的完整原因分类及对应排查方案,结合JVM运行机制和常见故障场景整理而成: 一、GC相关暂停​​ 1. ​​安全点(Safepoint)阻塞​​ ​​现象​​:JVM暂停但无GC日志,日志显示No GCs detected。​​原因​​:JVM等待所有线程进入安全点(如…...

20个超级好用的 CSS 动画库

分享 20 个最佳 CSS 动画库。 它们中的大多数将生成纯 CSS 代码&#xff0c;而不需要任何外部库。 1.Animate.css 一个开箱即用型的跨浏览器动画库&#xff0c;可供你在项目中使用。 2.Magic Animations CSS3 一组简单的动画&#xff0c;可以包含在你的网页或应用项目中。 3.An…...

接口自动化测试:HttpRunner基础

相关文档 HttpRunner V3.x中文文档 HttpRunner 用户指南 使用HttpRunner 3.x实现接口自动化测试 HttpRunner介绍 HttpRunner 是一个开源的 API 测试工具&#xff0c;支持 HTTP(S)/HTTP2/WebSocket/RPC 等网络协议&#xff0c;涵盖接口测试、性能测试、数字体验监测等测试类型…...

通过 Ansible 在 Windows 2022 上安装 IIS Web 服务器

拓扑结构 这是一个用于通过 Ansible 部署 IIS Web 服务器的实验室拓扑。 前提条件&#xff1a; 在被管理的节点上安装WinRm 准备一张自签名的证书 开放防火墙入站tcp 5985 5986端口 准备自签名证书 PS C:\Users\azureuser> $cert New-SelfSignedCertificate -DnsName &…...

tauri项目,如何在rust端读取电脑环境变量

如果想在前端通过调用来获取环境变量的值&#xff0c;可以通过标准的依赖&#xff1a; std::env::var(name).ok() 想在前端通过调用来获取&#xff0c;可以写一个command函数&#xff1a; #[tauri::command] pub fn get_env_var(name: String) -> Result<String, Stri…...

协议转换利器,profinet转ethercat网关的两大派系,各有千秋

随着工业以太网的发展&#xff0c;其高效、便捷、协议开放、易于冗余等诸多优点&#xff0c;被越来越多的工业现场所采用。西门子SIMATIC S7-1200/1500系列PLC集成有Profinet接口&#xff0c;具有实时性、开放性&#xff0c;使用TCP/IP和IT标准&#xff0c;符合基于工业以太网的…...

yaml读取写入常见错误 (‘cannot represent an object‘, 117)

错误一&#xff1a;yaml.representer.RepresenterError: (‘cannot represent an object’, 117) 出现这个问题一直没找到原因&#xff0c;后面把yaml.safe_dump直接替换成yaml.dump&#xff0c;确实能保存&#xff0c;但出现乱码&#xff1a; 放弃yaml.dump&#xff0c;又切…...