【踩坑日记18】如何在config.yam文件夹中添加新的参数?

想在config.yam文件夹中加入lora的相关参数,即加入:

train:
  lora:
    rank: 16
    alpha: 32
    dropout: 0.05
    bias: "none"
    task_type: "CAUSAL_LM"
    # use_dora:
    # init_lora_weights:

问题1

问题描述:

TypeError: __init__() got an unexpected keyword argument 'lora'

问题分析:

代码中,没有初始化’lora’参数

问题解决

在定义train参数的最后加上lora: dict,即

	pipeline: str  # One of the pipelines in framework.pipeline
    orchestrator: str  # One of the orchestrators
	logging_dir: str = "logs"
    checkpoint_dir: str = "ckpts"
    project_name: str = "trlx"
    seed: int = 1000
    eval_only: bool = False
    mixin: bool = False
    max_grad_norm: float = -1
    
    lora: dict

问题2

问题描述:

TypeError: non-default argument 'lora' follows default argument

问题分析:

原因是将没有默认值的参数在定义时放在了有默认值的参数的后面

问题解决:

改换参数顺序,即:

    pipeline: str  # One of the pipelines in framework.pipeline
    orchestrator: str  # One of the orchestrators
    
    lora: dict

    logging_dir: str = "logs"
    checkpoint_dir: str = "ckpts"
    project_name: str = "trlx"
    seed: int = 1000
    eval_only: bool = False
    mixin: bool = False
    max_grad_norm: float = -1

问题3

问题描述:

AttributeError: 'dict' object has no attribute 'rank'

问题解决:

代码由:

gpt_lora_config = LoraConfig(
            r=self.config.train.lora.rank,
            lora_alpha=self.config.train.lora.alpha,
            lora_dropout=self.config.train.lora.dropout,
            bias=self.config.train.lora.bias,
            task_type=self.config.train.lora.task_type,
        )

改为:

gpt_lora_config = LoraConfig(
            r=self.config.train.lora["rank"],
            lora_alpha=self.config.train.lora["alpha"],
            lora_dropout=self.config.train.lora["dropout"],
            bias=self.config.train.lora["bias"],
            task_type=self.config.train.lora["task_type"],
        )

参考

python报错:non-default argument follows default argument 解决方法

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值