Heuristic:AI4Finance Foundation FinGPT Model Specific Tokenization
| Knowledge Sources | |
|---|---|
| Domains | NLP, Deep_Learning |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
Apply model-specific tokenizer configurations (padding side, EOS/PAD token overrides) and exclude MPT from gradient checkpointing to avoid known compatibility issues.
Description
Different base model architectures (Qwen, MPT, Llama2, ChatGLM2, Falcon, etc.) have different tokenizer requirements and training compatibility. FinGPT training code applies model-specific fixes: Qwen requires custom EOS and PAD token IDs; MPT requires `padding_side="right"` and is excluded from gradient checkpointing; all models need pad token validation with fallback to adding a `[PAD]` special token. The `lora_module_dict` maps each model to its attention layer names for LoRA target modules.
Usage
Use this heuristic when switching base models in LoRA training or benchmark evaluation. Apply the correct tokenizer settings and LoRA module mapping for each model architecture.
The Insight (Rule of Thumb)
- Action: Set model-specific tokenizer padding side, EOS/PAD tokens; validate pad token; apply correct LoRA target modules.
- Value: Qwen: `eos_token_id=convert_tokens_to_ids()`, `pad_token_id=convert_tokens_to_ids('<|extra_0|>')`. MPT: `padding_side="right"`, no gradient checkpointing. Default: `padding_side="left"`.
- Trade-off: Requires model-specific branching code; prevents tokenization errors and training instability.
- Compatibility: See `lora_module_dict` for supported models and their target module names.
Reasoning
Tokenizer architectures vary significantly across model families. Qwen uses non-standard special tokens that differ from the default EOS/PAD. MPT's architecture is incompatible with gradient checkpointing, causing errors if enabled. Llama2, ChatGLM2, and Falcon use `query_key_value` or `q_proj`/`k_proj`/`v_proj` as attention module names, which must be correctly targeted by LoRA. Missing pad tokens cause batch collation errors; the fallback adds a `[PAD]` token and resizes embeddings.
Code Evidence
Model-specific tokenizer settings from `fingpt/FinGPT_Benchmark/train_lora.py:62-70`:
if args.base_model != 'mpt':
tokenizer.padding_side = "left"
if args.base_model == 'qwen':
tokenizer.eos_token_id = tokenizer.convert_tokens_to_ids('')
tokenizer.pad_token_id = tokenizer.convert_tokens_to_ids('<|extra_0|>')
if not tokenizer.pad_token or tokenizer.pad_token_id == tokenizer.eos_token_id:
tokenizer.add_special_tokens({'pad_token': '[PAD]'})
model.resize_token_embeddings(len(tokenizer))
LoRA module mapping from `fingpt/FinGPT_Benchmark/utils.py:10-21`:
lora_module_dict = {
'chatglm2': ['query_key_value'],
'falcon': ['query_key_value'],
'bloom': ['query_key_value'],
'internlm': ['q_proj', 'k_proj', 'v_proj'],
'llama2': ['q_proj', 'k_proj', 'v_proj'],
'qwen': ["c_attn"],
'mpt': ['Wqkv'],
...
}
MPT gradient checkpointing exclusion from `fingpt/FinGPT_Benchmark/train_lora.py:134-135`:
if not args.base_model == 'mpt':
model.gradient_checkpointing_enable()