Model reference · open weights

codegen2-16B_P

LLMs Salesforce Text gen 1 build Open weights 22k dl/mo

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.

  • Salesforce's codegen2-16B_P is an autoregressive language model designed for program synthesis and code infilling.
  • It supports multiple programming languages including Python, Java, and C++, and operates with a context length of 2048 tokens.
  • The model is released under the Apache 2.0 license.

Summary of the Salesforce/codegen2-16B_P model card, 2026-10-01

What it is

Released bySalesforce
Released2023-04-26
VRAM64.3 GB for the weights

What it runs on

Memory and cards for codegen2-16B_P (BF16)

64.3 GBweights, file size
836 MBcache per 1K tokens
784 MBruntime overhead, at least
2,048 tokenscontext max
CardRequests at onceContext maxMemory
2K each
RTX 3060 12 GB … L40S 48 GB
6 smaller cards
——
A100 80 GB7all 2K78.2 GB
H100 80 GB5all 2K78.1 GB
RTX PRO 6000 Blackwell 96 GB14all 2K93.8 GB
DGX Spark (GB10) 128 GB unified22all 2K107 GB
H200 141 GB40all 2K138 GB
B200 180 GB62all 2K176 GB
2× L40S 48 GB
tensor parallel
12all 2K44.0 GB a card
4× RTX 4090 24 GB
tensor parallel
15all 2K23.4 GB a card
4× RTX 3090 24 GB
tensor parallel
15all 2K23.4 GB a card
4× RTX 5090 32 GB
tensor parallel
33all 2K31.0 GB a card
2× H100 80 GB
tensor parallel
48all 2K78.1 GB a card
2× A100 80 GB
tensor parallel
52all 2K78.2 GB a card
Memory needed at each load
Requests at once2K tokens each
166.8 GB
573.6 GB
878.7 GB
1692.4 GB
32120 GB
64175 GB

One card, with vLLM's small-card settings.

From the model card

What Salesforce says about codegen2-16B_P

Read the model card

Model description

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.

How to use

This model can be easily loaded using the AutoModelForCausalLM functionality.

Causal sampling

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))

Infill sampling

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.
  • ``: Separator token between the suffix and the infilled sample. See below.
  • ``: "End-Of-Mask" token that model will output at the end of infilling. You may use this token to truncate the output.

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

  1. Inserting `` token in place of cursor position
  2. Append `` token to indicate the boundary
  3. Insert another `` to indicate which mask we want to infill.

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 ``.

Training data

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.

Training procedure

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.

Evaluation results

We evaluate our models on HumanEval and HumanEval-Infill. Please refer to the paper for more details.

Intended use and limitations

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.

Ethical Considerations

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.

BibTeX entry and citation info

@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.

© 2026 AxForge · EU-hosted AI infrastructure Pricing Docs Trust Privacy Terms