-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert_to_no_embedding.py
60 lines (48 loc) · 1.49 KB
/
convert_to_no_embedding.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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
This script will remove the embedding of a model, include the final projection.
"""
from dataclasses import dataclass, field
from transformers import (
AutoConfig,
AutoModelForCausalLM,
AutoTokenizer,
HfArgumentParser
)
@dataclass
class ModelArguments:
"""
Arguments pertaining to which model/config/tokenizer we are going to fine-tune, or train from scratch.
"""
input: str = field(
default=None,
metadata={
"help": (
"The input model path."
)
},
)
output: str = field(
default=None,
metadata={
"help": (
"The output model path."
)
},
)
def main():
# See all possible arguments in src/transformers/training_args.py
# or by passing the --help flag to this script.
# We now keep distinct sets of args, for a cleaner separation of concerns.
parser = HfArgumentParser((ModelArguments,))
(model_args, ) = parser.parse_args_into_dataclasses()
config = AutoConfig.from_pretrained(model_args.input)
assert config.model_type == "llama"
tokenizer = AutoTokenizer.from_pretrained(model_args.input)
model = AutoModelForCausalLM.from_pretrained(model_args.input, config=config)
del model.model.embed_tokens
del model.lm_head
model.save_pretrained(model_args.output)
tokenizer.save_pretrained(model_args.output)
config.save_pretrained(model_args.output)
if __name__ == '__main__':
main()