Extending the parameter count of a large language model (LLM) from 235B to 256B without retraining, quality loss, or requiring massive GPU resources is a non-trivial task, but there are a few theoretical approaches you could explore. Here’s how you might do it:
1. Add Dummy Parameters (Zero Padding)
The simplest way is to add "dummy" parameters that do nothing initially but can be activated later. Here’s how:
- Expand weight matrices: If your model is based on transformer layers, you can pad the weight matrices (e.g.,
W_q, W_k, W_v, W_ffn) with zeros or near-zero values.
- Example: If a weight matrix is
[d_model × d_head], you could expand it to [d_model × (d_head + delta)] where delta is the extra dimension.
- No impact on inference: If the new parameters are zero (or very small random values), they won’t affect the model’s output.
- Later fine-tuning: When you fine-tune, these parameters can be trained to become useful.
2. Expand Hidden Dimensions (with Identity Initialization)
- If the model uses feed-forward networks (FFN), you can increase the intermediate dimension (
d_ff) by adding extra neurons initialized to near-zero (or identity-mapped) values.
- Example: If
d_ff = 14336, you could expand it to d_ff = 15360 (or whatever gets you to 256B).
- Initialize new weights such that they do not change the output (e.g., zero weights + residual connection).
3. Add Extra (Disabled) Attention Heads
- If the model uses multi-head attention, you could add extra attention heads initialized to near-zero values.
- These heads won’t contribute to the output initially but can be trained later.
4. Use a "Scaling Trick" (e.g., LoRA-like Expansion)
- Instead of modifying the base model, you could add a parallel low-rank adapter (like LoRA) but keep its weights frozen at zero.
- Later, you can unfreeze and train these extra parameters.
Key Considerations
- No quality loss: The new parameters must be initialized in a way that doesn’t change the model’s behavior (e.g., zeros or identity-mapped).
- No extra compute during inference: The new parameters should not significantly increase memory or FLOPs (though technically, they will add a tiny overhead).
- Fine-tuning later: When you train, only the new parameters (or a subset) should be updated to avoid catastrophic forgetting.
Example Implementation (PyTorch-style Pseudocode)
import torch
def expand_linear_layer(layer, new_out_features):
old_out = layer.out_features
expansion = new_out_features - old_out
# Create new weight matrix (padded with zeros)
new_weight = torch.zeros((new_out_features, layer.in_features))
new_weight[:old_out, :] = layer.weight.data
# Create new bias (padded with zeros)
new_bias = torch.zeros(new_out_features)
new_bias[:old_out] = layer.bias.data
# Replace the layer's parameters
layer.weight = torch.nn.Parameter(new_weight)
layer.bias = torch.nn.Parameter(new_bias)
layer.out_features = new_out_features
# Apply to all relevant layers in the model
for layer in model.ffn_layers:
expand_linear_layer(layer, new_size=layer.out_features + delta)
Final Notes
- This is a hacky but functional way to increase parameter count without retraining.
- The new parameters will be redundant at first but can be trained later.
- You might need to adjust model parallelism if the original model was sharded across GPUs.
Would you like a more specific approach for a particular architecture (e.g., GPT-3, LLaMA, etc.)?