Principle:AI4Finance Foundation FinGPT Model Weight Conversion
| Knowledge Sources | |
|---|---|
| Domains | Model_Conversion, LLM, NLP |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
A model transformation technique that converts raw checkpoint weights from a proprietary format (e.g., Meta LLaMA) into the HuggingFace Transformers format for cross-framework compatibility.
Description
Model weight conversion handles the differences in tensor naming, sharding, rotary embedding layout, and configuration schema between the source checkpoint format and the target framework. The process involves: reading params.json, loading checkpoint shards, permuting rotary embedding weights, concatenating/sharding attention and feed-forward tensors, and writing a LlamaConfig + model checkpoint in the target format.
Usage
Use this principle when you need to load a model released in a non-HuggingFace format (e.g., raw Meta LLaMA weights) into HuggingFace Transformers for fine-tuning or inference.
Theoretical Basis
Key transformation: rotary embedding weight permutation. The original LLaMA checkpoint stores rotary weights in a sliced layout that must be permuted to match the HuggingFace implementation:
# Abstract permutation (not real implementation)
def permute(w, n_heads, dim1, dim2):
return w.view(n_heads, dim1 // n_heads // 2, 2, dim2) \
.transpose(1, 2).reshape(dim1, dim2)
Sharding: `NUM_SHARDS` maps model sizes to checkpoint shard counts (7B=1, 13B=2, 30B=4, 65B/70B=8).