-
Notifications
You must be signed in to change notification settings - Fork 1
/
save_pretrained.py
25 lines (21 loc) · 1.19 KB
/
save_pretrained.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from transformers import AutoTokenizer, AutoModelForCausalLM, AutoModel, RobertaModel, RobertaForMaskedLM
import torch
'''save all model that may used in later training'''
tokenizer = AutoTokenizer.from_pretrained("roberta-base")
tokenizer.save_pretrained("huggingface/roberta_head/")
model = RobertaForMaskedLM.from_pretrained("roberta-base")
model.save_pretrained("huggingface/roberta_head/")
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
tokenizer.save_pretrained("huggingface/bert/")
model = AutoModel.from_pretrained("bert-base-uncased")
model.save_pretrained("huggingface/bert/")
tokenizer = AutoTokenizer.from_pretrained("roberta-base")
tokenizer.save_pretrained("huggingface/roberta/")
model = AutoModel.from_pretrained("roberta-base")
model.save_pretrained("huggingface/roberta/")
token = "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"
model_dir = "meta-llama/Llama-2-7b-chat-hf"
tokenizer = AutoTokenizer.from_pretrained(model_dir, use_fast=True, lstrip=False, token=token)
tokenizer.save_pretrained("huggingface/llama2/")
model=AutoModelForCausalLM.from_pretrained(model_dir, token=token, device_map='cpu', use_cache=True, torch_dtype = torch.bfloat16)
model.save_pretrained("huggingface/llama2/")