Views
No views yet
pip install hf-hub-ctranslate2>=2.0.8 ct2-transformers-converter --model Salesforce/codegen2-3_7B --output_dir /home/michael/tmp-ct2fast-codegen2-3_7B --force --copy_files merges.txt tokenizer.json README.md tokenizer_config.json vocab.json special_tokens_map.json added_tokens.json configuration_codegen.py .gitattributes --quantization float16compute_type=int8_float16 for device="cuda"compute_type=int8 for device="cpu"1from hf_hub_ctranslate2 import TranslatorCT2fromHfHub, GeneratorCT2fromHfHub
2from transformers import AutoTokenizer
3
4model_name = "michaelfeil/ct2fast-codegen2-3_7B"
5# use either TranslatorCT2fromHfHub or GeneratorCT2fromHfHub here, depending on model.
6model = GeneratorCT2fromHfHub(
7 # load in int8 on CUDA
8 model_name_or_path=model_name,
9 device="cuda",
10 compute_type="int8_float16",
11 # tokenizer=AutoTokenizer.from_pretrained("Salesforce/codegen2-3_7B")
12)
13outputs = model.generate(
14 text=["def print_hello_world():", "def hello_name(name:"],
15 max_length=64
16)
17print(outputs)1B, 3.7B, 7B, 16B.AutoModelForCausalLM functionality.1from transformers import AutoTokenizer, AutoModelForCausalLM
2tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen2-3_7B")
3model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-3_7B", 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-3_7B")
3model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-3_7B", 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():\n "
11suffix = " return name"
12text = format(prefix, suffix)
13input_ids = tokenizer(text, return_tensors="pt").input_ids
14generated_ids = model.generate(input_ids, max_length=128)
15print(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}