-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NewFeature] add paddlenlp command #3538
Conversation
Cool features! 🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commands目录改为cli是否会更简洁?
cool,赞成, 那我调整成 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@guoshengCS ready for review
paddlenlp/cli/converter.py
Outdated
def convert_from_online_model(model_name: str, cache_dir: str, output_dir): | ||
"""convert the model which is not maintained in paddlenlp community, eg: vblagoje/bert-english-uncased-finetuned-pos | ||
|
||
TODO(wj-Mcat): to deeply test this method | ||
|
||
Args: | ||
model_name (str): the name of model | ||
cache_dir (str): the cache_dir to save pytorch model | ||
output_dir (_type_): the output dir | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
由于时间原因,现在暂不测试这个函数,等模型中心弄完之后再来深入测试online_convert
的相关功能。
logger.info("download community model configuration from server ...") | ||
remote_community_model_path = os.path.join( | ||
COMMUNITY_MODEL_PREFIX, COMMUNITY_MODEL_CONFIG_FILE_NAME) | ||
cache_dir = os.path.join(MODEL_HOME) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
将community_models.json
缓存文件放到~/.paddlenlp/models
目录下。
if model_config_file is not None: | ||
with open(model_config_file, 'r', encoding='utf-8') as f: | ||
config = json.load(f) | ||
config = self.convert_config(config) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
看这个convert_config默认直接用hf的,当前config是能直接使用hf的不需要任何调整是吗,version这些需要调整吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
对于未来模型理论上在参数上应该和hf保持一致,而且都是使用PretrainedConfig,所以不做任何调整都是可以使用的。
对于旧模型,是需要重写convert_config
函数,调整成为BaseModel构造函数中的参数列表。
不过,version
理论上是需要删除的,我也会去排查一下其他需要删除的字段。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
我这边添加了一个remove_transformer_unused_fields
方法来过滤不需要字段。
此外如果参数名称和hf 模型保持一致的话,只需要调整config_fields_to_be_removed
字段即可实现configuration的自动转化。
paddlenlp/utils/converter.py
Outdated
|
||
self.compare_model_state_dicts(paddle_model, pytorch_model, | ||
name_mappings) | ||
del paddle_model, pytorch_model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是否就paddle跑完结果就及时del然后跑pytorch的,避免更多的显存占用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯嗯,确实,这样能够合理利用现存空间。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
paddlenlp/cli/converter.py
Outdated
|
||
|
||
def convert_from_local_file(weight_file_path: str, output: str): | ||
"""convert from the local weitht file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
weitht -> weight
PR types
New features
PR changes
APIs
Description
add
paddlenlp
command tools to do more fancy things, eg: search models, download models and so on ...