Skip to content
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

Merged
merged 49 commits into from
Nov 16, 2022
Merged

Conversation

wj-Mcat
Copy link
Contributor

@wj-Mcat wj-Mcat commented Oct 22, 2022

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 ...

@ZeyuChen
Copy link
Member

Cool features! 🎉

Copy link
Member

@ZeyuChen ZeyuChen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commands目录改为cli是否会更简洁?

ZeyuChen
ZeyuChen previously approved these changes Oct 22, 2022
@wj-Mcat
Copy link
Contributor Author

wj-Mcat commented Oct 25, 2022

commands目录改为cli是否会更简洁?

cool,赞成, 那我调整成cli

@wj-Mcat
Copy link
Contributor Author

wj-Mcat commented Nov 1, 2022

paddlenlp search的示例界面如下所示:

image

Copy link
Contributor Author

@wj-Mcat wj-Mcat left a 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

Comment on lines 95 to 104
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
"""
Copy link
Contributor Author

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)
Copy link
Contributor Author

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)
Copy link
Contributor

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这些需要调整吗

Copy link
Contributor Author

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理论上是需要删除的,我也会去排查一下其他需要删除的字段。

Copy link
Contributor Author

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的自动转化。


self.compare_model_state_dicts(paddle_model, pytorch_model,
name_mappings)
del paddle_model, pytorch_model
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

是否就paddle跑完结果就及时del然后跑pytorch的,避免更多的显存占用

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯嗯,确实,这样能够合理利用现存空间。

wawltor
wawltor previously approved these changes Nov 16, 2022
Copy link
Collaborator

@wawltor wawltor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

guoshengCS
guoshengCS previously approved these changes Nov 16, 2022
Copy link
Contributor

@guoshengCS guoshengCS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM



def convert_from_local_file(weight_file_path: str, output: str):
"""convert from the local weitht file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weitht -> weight

@wj-Mcat wj-Mcat merged commit d3d0592 into PaddlePaddle:develop Nov 16, 2022
@wj-Mcat wj-Mcat deleted the add-cli branch November 16, 2022 23:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants