Views
No views yet
python /home/michael/fauxpilot/converter/codegen_gptj_convert.py --code_model Salesforce/codegen2-7B /home/michael/tmp-codegen2-7B-gptj1B, 3.7B, 7B, 16B.AutoModelForCausalLM functionality.1from transformers import AutoTokenizer, AutoModelForCausalLM
2tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen2-16B")
3model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-16B", trust_remote_code=True, revision="main")
4
5text = "def hello_world():"
6input_ids = tokenizer(text, return_tensors="pt").input_ids
7generated_ids = model.generate(input_ids, max_length=128)
8print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))<mask_N>: N-th span to be masked. In practice, use <mask_1> to where you want to sample infill.<sep>: Seperator token between the suffix and the infilled sample. See below.<eom>: "End-Of-Mask" token that model will output at the end of infilling. You may use this token to truncate the output.1def hello_world():
2 |
3 return name<mask_1> token in place of cursor position<sep> token to indicate the boundary<mask_1> to indicate which mask we want to infill.1from transformers import AutoTokenizer, AutoModelForCausalLM
2tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen2-16B")
3model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-16B", trust_remote_code=True, revision="main")
4
5
6def format(prefix, suffix):
7 return prefix + "<mask_1>" + suffix + "<|endoftext|>" + "<sep>" + "<mask_1>"
8
9
10prefix = "def hello_world():
11 "
12suffix = " return name"
13text = format(prefix, suffix)
14input_ids = tokenizer(text, return_tensors="pt").input_ids
15generated_ids = model.generate(input_ids, max_length=128)
16print(tokenizer.decode(generated_ids[0], skip_special_tokens=False)[len(text):])<eom>.c, c++, c-sharp, dart, go, java, javascript, kotlin, lua, php, python, ruby, rust, scala, shell, sql, swift, typescript, vue.1@article{Nijkamp2023codegen2,
2 title={CodeGen2: Lessons for Training LLMs on Programming and Natural Languages},
3 author={Nijkamp, Erik and Hayashi, Hiroaki and Xiong, Caiming and Savarese, Silvio and Zhou, Yingbo},
4 journal={arXiv preprint},
5 year={2023}
6}