Model reference · open weights
codegen2-16B_P is an open-weight language model from Salesforce. codegen2-16B_P (BF16) weighs 64.3 GB; the smallest configuration that runs it is H100 80 GB.
Summary of the Salesforce/codegen2-16B_P model card, 2026-10-01
What it is
| Released by | Salesforce |
|---|---|
| Released | 2023-04-26 |
| VRAM | 64.3 GB for the weights |
What it runs on
| Card | Requests at once | Context max | Memory |
|---|---|---|---|
| 2K each | |||
| RTX 3060 12 GB … L40S 48 GB 6 smaller cards | — | — | |
| A100 80 GB | 7 | all 2K | 78.2 GB |
| H100 80 GB | 5 | all 2K | 78.1 GB |
| RTX PRO 6000 Blackwell 96 GB | 14 | all 2K | 93.8 GB |
| DGX Spark (GB10) 128 GB unified | 22 | all 2K | 107 GB |
| H200 141 GB | 40 | all 2K | 138 GB |
| B200 180 GB | 62 | all 2K | 176 GB |
| 2× L40S 48 GB tensor parallel | 12 | all 2K | 44.0 GB a card |
| 4× RTX 4090 24 GB tensor parallel | 15 | all 2K | 23.4 GB a card |
| 4× RTX 3090 24 GB tensor parallel | 15 | all 2K | 23.4 GB a card |
| 4× RTX 5090 32 GB tensor parallel | 33 | all 2K | 31.0 GB a card |
| 2× H100 80 GB tensor parallel | 48 | all 2K | 78.1 GB a card |
| 2× A100 80 GB tensor parallel | 52 | all 2K | 78.2 GB a card |
| Requests at once | 2K tokens each |
|---|---|
| 1 | 66.8 GB |
| 5 | 73.6 GB |
| 8 | 78.7 GB |
| 16 | 92.4 GB |
| 32 | 120 GB |
| 64 | 175 GB |
One card, with vLLM's small-card settings.
From the model card
CodeGen2 is a family of autoregressive language models for program synthesis, introduced in the paper:
CodeGen2: Lessons for Training LLMs on Programming and Natural Languages by Erik Nijkamp*, Hiroaki Hayashi*, Caiming Xiong, Silvio Savarese, Yingbo Zhou.
Unlike the original CodeGen model family (i.e., CodeGen1), CodeGen2 is capable of infilling, and supports more programming languages.
Four model sizes are released: 1B, 3.7B, 7B, 16B.
This model can be easily loaded using the AutoModelForCausalLM functionality.
For regular causal sampling, simply generate completions given the context:
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen2-16B")
model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-16B", trust_remote_code=True, revision="main")
text = "def hello_world():"
input_ids = tokenizer(text, return_tensors="pt").input_ids
generated_ids = model.generate(input_ids, max_length=128)
print(tokenizer.decode(generated_ids[0], skip_special_tokens=True))
For infill sampling, we introduce three new special token types:
: N-th span to be masked. In practice, use to where you want to sample infill.For example, if we want to generate infill for the following cursor position of a function:
def hello_world():
|
return name
we construct an input to the model by
The final snippet looks as follows:
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("Salesforce/codegen2-16B")
model = AutoModelForCausalLM.from_pretrained("Salesforce/codegen2-16B", trust_remote_code=True, revision="main")
def format(prefix, suffix):
return prefix + "" + suffix + "" + "" + ""
prefix = "def hello_world():\n "
suffix = " return name"
text = format(prefix, suffix)
input_ids = tokenizer(text, return_tensors="pt").input_ids
generated_ids = model.generate(input_ids, max_length=128)
print(tokenizer.decode(generated_ids[0], skip_special_tokens=False)[len(text):])
You might want to truncate the model output with ``.
This checkpoint is trained on the stricter permissive subset of the deduplicated version of the Stack dataset (v1.1). Supported languages (and frameworks) are as follows:
c, c++, c-sharp, dart, go, java, javascript, kotlin, lua, php, python, ruby, rust, scala, shell, sql, swift, typescript, vue.
CodeGen2 was trained using cross-entropy loss to maximize the likelihood of sequential inputs. The input sequences are formatted in two ways: (1) causal language modeling and (2) file-level span corruption. Please refer to the paper for more details.
We evaluate our models on HumanEval and HumanEval-Infill. Please refer to the paper for more details.
As an autoregressive language model, CodeGen2 is capable of extracting features from given natural language and programming language texts, and calculating the likelihood of them. However, the model is intended for and best at program synthesis, that is, generating executable code given English prompts, where the prompts should be in the form of a comment string. The model can complete partially-generated code as well.
This release is for research purposes only in support of an academic paper. Our models, datasets, and code are not specifically designed or evaluated for all downstream purposes. We strongly recommend users evaluate and address potential concerns related to accuracy, safety, and fairness before deploying this model. We encourage users to consider the common limitations of AI, comply with applicable laws, and leverage best practices when selecting use cases, particularly for high-risk scenarios where errors or misuse could significantly impact people’s lives, rights, or safety. For further guidance on use cases, refer to our AUP and AI AUP.
@article{Nijkamp2023codegen2,
title={CodeGen2: Lessons for Training LLMs on Programming and Natural Languages},
author={Nijkamp, Erik and Hayashi, Hiroaki and Xiong, Caiming and Savarese, Silvio and Zhou, Yingbo},
journal={arXiv preprint},
year={2023}
}
Quoted from the model card on Hugging Face. The full card is behind the Hugging Face link above.