|
1 | 1 | import argparse
|
2 | 2 | import glob
|
3 |
| -import os |
| 3 | +import os, json |
4 | 4 | import torch
|
5 | 5 | from transformers import AutoModel, AutoTokenizer
|
6 | 6 |
|
|
16 | 16 | mm_tensors = [k for k, v in checkpoint.items() if k.startswith("resampler")]
|
17 | 17 |
|
18 | 18 | # store these tensors in a new dictionary and torch.save them
|
19 |
| -projector = {name: checkpoint[name].float() for name in mm_tensors} |
| 19 | +projector = {name: checkpoint[name].float().cpu() for name in mm_tensors} |
20 | 20 | torch.save(projector, f"{args.model}/llava.projector")
|
21 | 21 |
|
22 | 22 | clip_tensors = [k for k, v in checkpoint.items() if k.startswith("vpm")]
|
23 | 23 | if len(clip_tensors) > 0:
|
24 |
| - clip = {name.replace("vpm.", ""): checkpoint[name].float() for name in clip_tensors} |
| 24 | + clip = {name.replace("vpm.", ""): checkpoint[name].float().cpu() for name in clip_tensors} |
25 | 25 | torch.save(clip, f"{args.model}/llava.clip")
|
26 | 26 |
|
27 | 27 | # added tokens should be removed to be able to convert Mistral models
|
|
42 | 42 | tok = AutoTokenizer.from_pretrained(args.model, trust_remote_code=True)
|
43 | 43 | tok.save_pretrained(f"{args.model}/MiniCPM")
|
44 | 44 | os.system(f"cp {args.model}/modeling_minicpm.py {args.model}/MiniCPM/modeling_minicpm.py")
|
| 45 | +os.system(f"cp {args.model}/tokenizer.json {args.model}/MiniCPM/tokenizer.json") |
| 46 | +with open(f"{args.model}/MiniCPM/tokenizer_config.json", "r") as f: |
| 47 | + d = json.load(f) |
| 48 | + d.pop("auto_map") |
| 49 | + d["tokenizer_class"] = "LlamaTokenizer" |
| 50 | + d.pop("add_prefix_space") |
| 51 | +with open(f"{args.model}/MiniCPM/tokenizer_config.json", "w") as f: |
| 52 | + json.dump(d, f, indent=2) |
| 53 | + |
45 | 54 |
|
46 | 55 | print("Done!")
|
47 | 56 | print(f"Now you can convert {args.model} to a regular LLaMA GGUF file.")
|
|
0 commit comments