Replies: 3 comments 5 replies
-
我对examples中各式各样的argparser写法有的有disable yapf 有的没有确实看了很难受,我觉得可以用新建的examples做几个样板间,然后发布对应的任务到社区看是否可以让社区小伙伴一起来完成所有examples的升级替换。如果升级就要把tap作为paddlenlp默认依赖,这时要确保tap的上游依赖是pure python且稳定,不会带来安装问题。 |
Beta Was this translation helpful? Give feedback.
1 reply
-
另外还需要考虑下这个tap 与trainer中PdAurmentParser的关系 是否可以统一以及会带来兼容性问题 |
Beta Was this translation helpful? Give feedback.
4 replies
-
如果主要是看中 tap 简洁性,且相较 PdAurmentParser 简洁主要体现在能从 comment 中获取help信息,是否考虑将这个能力加到 PdAurmentParser 上,支持其也能够和 tap 相同的方式来定义args。 考量:
from typing import Set
from tap import Tap
class Config(Tap):
model_name: str = "bert" # the name of model.
max_steps: Set[int] = (100, 100, 100, 100, 100, 100, 100, 100, 100, 100) # the max steps of traning stage
device: str = "gpu" # the device info
def test(self):
print('test')
config: Config = Config().parse_args()
print(config) # 打印的config会包含test方法的信息,也是因为Tap实现的相对简单 from typing import Set
from tap import Tap
# max_steps 的定义换行导致抽取不出来
class Config(Tap):
model_name: str = "bert" # the name of model.
max_steps: Set[int] = (100, 100, 100, 100, 100, 100, 100, 100, 100, 100
) # the max steps of traning stage
device: str = "gpu" # the device info
config: Config = Config().parse_args() from dataclasses import dataclass
from typing import Set
from tap import Tap
# 使用装饰器导致失败
@dataclass
class Config(Tap):
model_name: str = "bert" # the name of model
max_steps: Set[int] = (100, 100, 100, 100, 100, 100, 100, 100, 100, 100) # the max steps of traning stage
device: str = "gpu" # the device info
config: Config = Config().parse_args()
这种情况下的推荐用法:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Introduction
Argument parser 作为一个参数解析工具,在
examples
里面存在大量的代码来定义。可是python官方库存在以下问题:train.py
,predict.py
,eval.py
文件都存在很多重复性参数定义,如model_name
,task_name
等字段解决方案
在此,推荐使用typed-argument-parser工具可解决以上问题。通过面向对象的方式来解决以上问题,在保证Argument Parser功能的基础上让代码更加简洁、易读。
在以上代码中:
type
字段model_path
字段由于没有设置值,故为requireddevice
设置了默认值,作用等价于argument中的default
字段缺点
如果是高级的argument parser用法的话,tap是不支持的,比如:
Beta Was this translation helpful? Give feedback.
All reactions