family codegen
GPT-J's parallel block and adjacent-pair rotary, with the queries, values and keys cut from one projection laid out as four groups of [q | v | k].
One block of the stack. Hover any part for its nnterp name; click to pin the card.
One block of the stack. Hover any part for its nnterp name; click to pin the card.
One block of the stack. Hover any part for its nnterp name; click to pin the card.
One block of the stack. Hover any part for its nnterp name; click to pin the card.
identity layers[i].input + self_attn.attention_output + mlp.mlp_output == layer_output
⚠︎ marks a value this checkpoint has only under some load: hover it for the condition.
What print(model) shows on Salesforce/codegen-350M-mono: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=1024, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 1024)
(layers): ModuleList(
(0-19): 20 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((1024,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=1024, out_features=3072, bias=False)
(o_proj/out_proj): Linear(in_features=1024, out_features=1024, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=1024, out_features=4096, bias=True)
(down_proj/fc_out): Linear(in_features=4096, out_features=1024, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-350M-multi: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=1024, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 1024)
(layers): ModuleList(
(0-19): 20 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((1024,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=1024, out_features=3072, bias=False)
(o_proj/out_proj): Linear(in_features=1024, out_features=1024, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=1024, out_features=4096, bias=True)
(down_proj/fc_out): Linear(in_features=4096, out_features=1024, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-350M-nl: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=1024, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 1024)
(layers): ModuleList(
(0-19): 20 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((1024,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=1024, out_features=3072, bias=False)
(o_proj/out_proj): Linear(in_features=1024, out_features=1024, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=1024, out_features=4096, bias=True)
(down_proj/fc_out): Linear(in_features=4096, out_features=1024, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((1024,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-2B-mono: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=2560, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 2560)
(layers): ModuleList(
(0-31): 32 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=2560, out_features=7680, bias=False)
(o_proj/out_proj): Linear(in_features=2560, out_features=2560, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=2560, out_features=10240, bias=True)
(down_proj/fc_out): Linear(in_features=10240, out_features=2560, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-2B-multi: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=2560, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 2560)
(layers): ModuleList(
(0-31): 32 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=2560, out_features=7680, bias=False)
(o_proj/out_proj): Linear(in_features=2560, out_features=2560, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=2560, out_features=10240, bias=True)
(down_proj/fc_out): Linear(in_features=10240, out_features=2560, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-2B-nl: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=2560, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 2560)
(layers): ModuleList(
(0-31): 32 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=2560, out_features=7680, bias=False)
(o_proj/out_proj): Linear(in_features=2560, out_features=2560, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=2560, out_features=10240, bias=True)
(down_proj/fc_out): Linear(in_features=10240, out_features=2560, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((2560,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-6B-mono: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=4096, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 4096)
(layers): ModuleList(
(0-32): 33 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((4096,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=4096, out_features=12288, bias=False)
(o_proj/out_proj): Linear(in_features=4096, out_features=4096, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=4096, out_features=16384, bias=True)
(down_proj/fc_out): Linear(in_features=16384, out_features=4096, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-6B-multi: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=4096, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 4096)
(layers): ModuleList(
(0-32): 33 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((4096,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=4096, out_features=12288, bias=False)
(o_proj/out_proj): Linear(in_features=4096, out_features=4096, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=4096, out_features=16384, bias=True)
(down_proj/fc_out): Linear(in_features=16384, out_features=4096, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-6B-nl: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=4096, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 4096)
(layers): ModuleList(
(0-32): 33 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((4096,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=4096, out_features=12288, bias=False)
(o_proj/out_proj): Linear(in_features=4096, out_features=4096, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=4096, out_features=16384, bias=True)
(down_proj/fc_out): Linear(in_features=16384, out_features=4096, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((4096,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-16B-mono: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=6144, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 6144)
(layers): ModuleList(
(0-33): 34 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=6144, out_features=18432, bias=False)
(o_proj/out_proj): Linear(in_features=6144, out_features=6144, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=6144, out_features=24576, bias=True)
(down_proj/fc_out): Linear(in_features=24576, out_features=6144, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-16B-multi: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=6144, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 6144)
(layers): ModuleList(
(0-33): 34 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=6144, out_features=18432, bias=False)
(o_proj/out_proj): Linear(in_features=6144, out_features=6144, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=6144, out_features=24576, bias=True)
(down_proj/fc_out): Linear(in_features=24576, out_features=6144, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)What print(model) shows on Salesforce/codegen-16B-nl: the native modules, standard names and every standard value with its layout.
CodeGenForCausalLM(
(lm_head): Linear(in_features=6144, out_features=51200, bias=True)
(generator): Generator(
(streamer): Streamer()
)
(embed_tokens): Embedding(51200, 6144)
(layers): ModuleList(
(0-33): 34 x CodeGenBlock(
(input_layernorm/ln_1): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(self_attn/attn): CodeGenAttention(
(attn_dropout): Dropout(p=0.0, inplace=False)
(resid_dropout): Dropout(p=0.0, inplace=False)
(qkv_proj): Linear(in_features=6144, out_features=18432, bias=False)
(o_proj/out_proj): Linear(in_features=6144, out_features=6144, bias=False)
(attention_queries) -> Queries [batch num_heads seq qk_head_dim]: The queries entering attention
(attention_keys) -> Keys [batch num_kv_heads seq qk_head_dim]: The keys entering attention
(attention_values) -> Values [batch num_kv_heads seq head_dim]: The values entering attention
(attention_scores) -> Pattern [batch num_heads query key]: The attention scores entering the softmax, masked then scaled, in fp32
(attention_head_outputs) -> HeadOutputs [batch seq num_heads head_dim]: The per-head outputs before the output projection
(attention_probabilities) -> Pattern [batch num_heads query key]: The attention pattern the values are mixed with
(attention_premix) -> HeadOutputs [batch seq num_heads head_dim]: Every head's output side by side, as the output projection takes it
(attention_output) -> Residual [batch seq hidden_size]: What the attention adds to the residual stream
)
(mlp): CodeGenMLP(
(fc_in): Linear(in_features=6144, out_features=24576, bias=True)
(down_proj/fc_out): Linear(in_features=24576, out_features=6144, bias=True)
(act_fn/act): NewGELUActivation()
(dropout): Dropout(p=0.0, inplace=False)
(mlp_activation) -> Neurons [batch seq intermediate_size]: The activation function's output
(mlp_neurons) -> Neurons [batch seq intermediate_size]: What the down projection receives: act(gate)·up on a gated MLP, the activation itself otherwise
(mlp_output) -> Residual [batch seq hidden_size]: What the MLP adds to the residual stream
)
(layer_mid): Unavailable: a parallel block: the attention and the MLP read the same input, so there is no stream between them
(mlp_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the MLP: the one norm feeds both sublayers
(layer_input) -> Residual [batch seq hidden_size]: The residual stream entering the block
(attention_norm_output) -> Residual [batch seq hidden_size]: The normed stream entering the attention
(mlp_input) -> Residual [batch seq hidden_size]: What the MLP is called with
(layer_output) -> Residual [batch seq hidden_size]: The residual stream leaving the block, a tensor even when the block returns a tuple
)
)
(norm): LayerNorm((6144,), eps=1e-05, elementwise_affine=True, bias=True)
(logits) -> Logits [batch seq vocab_size]: The logits the model returns, after anything it does past lm_head (a softcap, a scale)
(token_embeddings) -> Residual [batch seq hidden_size]: The embedding module's output; layers[0].input is what enters the first block
(final_norm_output) -> Residual [batch seq hidden_size]: The residual stream after the final norm, what lm_head reads
(lm_head_output) -> Logits [batch seq vocab_size]: The head's logits before anything the model does past lm_head (a softcap, a scale)
(next_token_probs) -> NextTokenProbs [batch vocab_size]: The next-token distribution at the last position; derived, read-only
(input_ids) -> Tokens [batch seq]: The token ids the model was called with
(attention_mask) -> Tokens [batch seq]: The attention mask the model was called with; zeros are padding
(input_size): [batch, seq] of the current call; read-only
)h = ln_1(x)
out = x + self_attn(h) + mlp(h)
ln_1 is the block's only norm. Its output is both self_attn.input and mlp.input, the same
tensor; input_layernorm is its alias, and the block has no post_attention_layernorm.
attention_output is out_proj's output and mlp_output is fc_out's, and nothing normalizes
either before the add. Nothing connects the two sublayers of one block: zeroing attention_output
leaves that block's mlp.input bit-identical, so block i's attention first reaches an MLP at
block i + 1.
with model.trace(prompt):
x = model.layers[2].input.save()
attn = model.layers[2].self_attn.attention_output.save()
mlp_in = model.layers[2].mlp.input.save()
mlp = model.layers[2].mlp.mlp_output.save()
out = model.layers[2].layer_output.save()
assert torch.equal(attn + mlp + x, out) # the block's own order
with model.trace(prompt):
model.layers[2].self_attn.attention_output[:] = 0
mlp_in_ablated = model.layers[2].mlp.input.save()
assert torch.equal(mlp_in, mlp_in_ablated)
The block's attn_weights are returned on every forward, not only under output_attentions:
model.layers[i].output[1] is the block's attention pattern, equal to
self_attn.attention_probabilities.
qkv_proj holds four groups of queries, values and keysself_attn.qkv_proj is one Linear from hidden_size to 3 * hidden_size without a bias
(out_proj has none either; fc_in and fc_out have one). The forward cuts its output into
mp_num = 4 groups, a constant in the source, and splits each group as [q | v | k]: values in
the middle, keys last. Group c holds heads c * num_heads / 4 to (c + 1) * num_heads / 4 - 1,
four heads per group on 350M. A split of the full width into three hidden_size blocks, in either
order, gets only the first group's queries right. Keys and values have num_heads heads; there is
no grouping of key/value heads.
attention_queries and attention_keys are read after the rotary, attention_values as split.
To get queries and keys before the rotary, regroup the projection's output in the same trace:
with model.trace(prompt):
qkv = model.layers[2].self_attn.source.self_qkv_proj_0.output.save()
q = model.layers[2].self_attn.attention_queries.save()
v = model.layers[2].self_attn.attention_values.save()
b, s, _ = qkv.shape
H, D = model.num_heads, model.head_dim
groups = qkv.view(b, s, 4, 3, H // 4, D) # 4 groups of [q | v | k]
q_pre, v_split, k_pre = (
groups[:, :, :, j].reshape(b, s, H, D).transpose(1, 2) for j in range(3)
)
assert torch.equal(v_split, v)
rot = model.config.rotary_dim # 32 of 64 on 350M
assert torch.equal(q_pre[..., rot:], q[..., rot:]) # past rotary_dim: not rotated
The weight's rows are in the same order: qkv_proj.weight.view(4, 3, num_heads // 4, head_dim,
hidden_size)[c, j, h] is head c * num_heads / 4 + h of the queries (j = 0), values (1) or
keys (2). An in-place edit of attention_queries, attention_keys or attention_values
reaches the scores or the head outputs: the three are the tensors _attn computes with.
rotary_dim is 32 of each head's 64 channels on 350M; the configs set 64 on every larger size, of
80 on 2B and of 256 on 6B and 16B. The rotation pairs adjacent channels (2i, 2i + 1) (GPT-J's
rotate_every_two), not the two halves (i, i + rotary_dim / 2) that rotate_half pairs on
Llama and GPT-NeoX; pair i turns by position · 10000^(-2i / rotary_dim). A de-rotation or a
frequency analysis written for rotate_half pairs the wrong channels here. The channels past
rotary_dim are the projection's output unchanged and carry no position.
attn_implementation="sdpa" fails at load; _attn is the only path. The mask holds the minimum
of the model's dtype, and it is added before the division by sqrt(head_dim), so a masked entry of
attention_scores is about that minimum divided by sqrt(head_dim). On 350M (head_dim 64) that
is about -8188 on the default float16 load and -4.25e37 on a float32 load: finite, and neither the
float16 nor the float32 minimum a mask test may look for. softmax(attention_scores) cast to the
model's dtype equals attention_probabilities exactly.
The configs set torch_dtype: float16 (2B-nl: float32), and a load without dtype keeps it,
on CPU too. The rotary multiplies by a float32 sin/cos buffer, so on that load attention_queries
is float32 while attention_keys is float16. The cache casts the keys back to the model's dtype,
and a trace runs with the cache on; under use_cache=False the keys stay float32. attention_values and
attention_probabilities are float16, attention_scores float32. q @ k.transpose(-1, -2) on
the two raises; cast first:
with model.trace(prompt):
q = model.layers[2].self_attn.attention_queries.save() # float32
k = model.layers[2].self_attn.attention_keys.save() # float16
scores = model.layers[2].self_attn.attention_scores.save()
recomputed = q @ k.float().transpose(-1, -2) / model.head_dim ** 0.5
recomputed equals scores wherever the mask lets a key through.
The load report lists each block's attn.causal_mask as unexpected: the files store a mask buffer
that transformers' class does not have, and the mask is built per call.
logits equals lm_head.output, and project_on_vocab applied to the last block's
layer_output equals logits exactly, ln_f's bias and lm_head's included. A logit lens
therefore adds the same vector at every block, whatever the input:
bias_logits = model.lm_head.weight @ model.norm.bias + model.lm_head.bias
On 350M-mono this vector has a standard deviation of 1.8 logits, against about 4 for a whole lens
readout at block 5 on a sample prompt. Most of that spread comes from ln_f.bias (lm_head.bias alone:
0.11), and its top tokens are \n, ,, -, ., _. Folding the norm into the unembedding keeps
both biases as one term.
wte and lm_head are separate matrices. The vocabulary is padded: 51200 rows against 50295
tokenizer tokens on -mono (50257 on -nl). On 350M-mono the 905 extra rows are not zero
(biases between -0.38 and -0.34); on a sample prompt their total probability at any position is
below 4e-6.
The -multi and -mono tokenizers are GPT-2's 50257 tokens, at the same ids, plus 38: one token
for each run of 2 to 31 spaces (ids 50286 down to 50257) and of 2 to 9 tabs (50294 down to 50287).
The -nl tokenizers are GPT-2's alone, so the same code prompt has different tokens and positions
on -nl than on the other two. On -multi and -mono a run of two or more spaces becomes one
token and the word after it loses its leading space, so an indented statement starts with the
bare word:
model.tokenizer.encode(" return x") # [50284, 7783, 2124]: ' ', 'return', ' x'
GPT-2 encodes the same text as three ' ' and ' return' (1441). A logit-lens or patching target
inside a block is the bare return (7783): after "def add(a, b):\n " 350M-mono puts 0.34 on
it. After the newline that opens a function body the model predicts the indent itself: after
"def add(a, b):\n" 350M-mono puts 0.80 on the four-space token.
The tokenizer adds no BOS: position 0 is the prompt's first token. <|endoftext|> (50256) is its
bos_token, eos_token and unk_token; the config's bos_token_id is 1, which is the token ".
Each size was released three times; the model cards and the paper (A Conversational Paradigm for Program Synthesis) describe the data:
-nl: trained on the Pile.-multi: initialized from -nl and trained further on BigQuery GitHub code in C, C++, Go,
Java, JavaScript and Python (119.2B tokens).-mono: initialized from -multi and trained further on BigPython (71.7B tokens of Python).The three share the architecture and the 51200-row embedding; the tokenizers differ (above). The sizes, from the configs:
rotary_dim 32rotary_dim 64rotary_dim 64rotary_dim 64Salesforce/codegen2-1B, codegen2-3_7B, codegen2-7B and codegen2-16B set
model_type: "codegen" and ship their own modeling code (auto_map). Without
trust_remote_code, transformers builds its own CodeGenForCausalLM, nnterp wraps it, and
support() reports every value available. But the 1B and 3.7B code cuts qkv_proj into 8 groups
(mp_num = 8), not 4, so the class mixes columns of the queries, values and keys. On a 13-line
Python sample codegen2-1B's loss is 8.93 as loaded and 0.34 after regrouping each
qkv_proj.weight from 8 groups of [q | v | k] to 4. The 7B and 16B code uses 4 groups. With
trust_remote_code=True the remote code fails to import: it imports transformers.onnx, which
transformers 5.20 does not have. CodeGen2.5 (Salesforce/codegen25-7b-mono, ...) is a LlamaForCausalLM
and loads as Llama.
CodeGen (CodeGenForCausalLM).
transformer.{wte, drop, h[i].{ln_1, attn, mlp}, ln_f} and lm_head. GPT-J's
parallel block: ln_1 feeds both sublayers and x + attn + mlp is summed in
the block, which returns (hidden_states, attn_weights). The attention projects
queries, values and keys (in that order) out of one fused qkv_proj laid out for
four TPU cores, applies rotary embeddings to the first rotary_dim channels, and
does its own arithmetic in _attn: an fp32 q @ k^T, the mask added, then
the division by sqrt(head_dim), softmax, a cast to the values' dtype,
attn_dropout, @ v. The model has no attention implementation but that one,
so attn_implementation never routes around it and the interior needs no eager
load. drop has no standard name.
CodeGen2 checkpoints (Salesforce/codegen2-*) declare model_type codegen,
but their own code lays qkv_proj out in eight groups (mp_num = 8); loaded
through transformers' class, which splits it in four, the queries, keys and values
are cut wrong and nothing reports it.