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

使用jittor加载模型的时候这个文件pytorch_model.bin.index.json是如何生成的? #348

Open
wanglaiqi opened this issue Jul 5, 2023 · 1 comment

Comments

@wanglaiqi
Copy link

def load_from_torch_shard_ckpt(model, ckpt_dir):
"""
Load sharded checkpoints directly from huggingface dir.
"""
with open(os.path.join(ckpt_dir, 'pytorch_model.bin.index.json')) as fp:
ckpt_index = json.load(fp)

total_size = ckpt_index['metadata']['total_size']
weight_map = ckpt_index['weight_map']

file_weight_map = {}
for key, value in weight_map.items():
    # key: param name; value: filename.
    if value not in file_weight_map:
        file_weight_map[value] = []
    file_weight_map[value].append(key)

load_from_map(model, ckpt_dir, file_weight_map)
@x54-729
Copy link
Contributor

x54-729 commented Jul 14, 2023

您好!pytorch_model.bin.index.json 就是 MOSS huggingface 仓库里的文件,这个文件是 huggingface 用来指示每个权重分别属于哪个权重文件的索引;用 jittor 加载模型的时候需要确保加载目录下要包含 config.json pytorch_model.bin.index.json.bin 后缀的权重。

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

No branches or pull requests

2 participants