Views
No views yet
pip install hf-hub-ctranslate2>=2.0.8ct2-transformers-converter --model Salesforce/codet5p-770m --output_dir /home/michael/tmp-ct2fast-codet5p-770m --force --copy_files merges.txt README.md tokenizer_config.json vocab.json special_tokens_map.json added_tokens.json .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-codet5p-770m"
5# use either TranslatorCT2fromHfHub or GeneratorCT2fromHfHub here, depending on model.
6model = TranslatorCT2fromHfHub(
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/codet5p-770m")
12)
13outputs = model.generate(
14 text=["def print_hello_world():", "def hello_name(name:"],
15 decode_tok_kwargs=dict(skip_special_tokens=True),
16 max_decoding_length=64,
17 end_token=["def"]
18)
19print(outputs)220M, CodeT5-large: 770M), CodeT5+ is pretrained with a diverse set of pretraining tasks including span denoising, causal language modeling, contrastive learning, and text-code matching to learn rich representations from both unimodal code data and bimodal code-text data.
Additionally, it employs a simple yet effective compute-efficient pretraining method to initialize the model components with frozen off-the-shelf LLMs such as CodeGen to efficiently scale up the model (i.e. 2B, 6B, 16B), and adopts a "shallow encoder and deep decoder" architecture.
Furthermore, it is instruction-tuned to align with natural language instructions (see our InstructCodeT5+ 16B) following Code Alpaca.T5ForConditionalGeneration functionality and employs the same tokenizer as original CodeT5.1from transformers import T5ForConditionalGeneration, AutoTokenizer
2
3checkpoint = "Salesforce/codet5p-770m"
4device = "cuda" # for GPU usage or "cpu" for CPU usage
5
6tokenizer = AutoTokenizer.from_pretrained(checkpoint)
7model = T5ForConditionalGeneration.from_pretrained(checkpoint).to(device)
8
9inputs = tokenizer.encode("def print_hello_world():<extra_id_0>", return_tensors="pt").to(device)
10outputs = model.generate(inputs, max_length=10)
11print(tokenizer.decode(outputs[0], skip_special_tokens=True))
12# ==> print "Hello World"c, c++, c-sharp, go, java, javascript, php, python, ruby.1@article{wang2023codet5plus,
2 title={CodeT5+: Open Code Large Language Models for Code Understanding and Generation},
3 author={Wang, Yue and Le, Hung and Gotmare, Akhilesh Deepak and Bui, Nghi D.Q. and Li, Junnan and Hoi, Steven C. H.},
4 journal={arXiv preprint},
5 year={2023}
6}