Environment:AI4Finance Foundation FinGPT PyTorch
| Knowledge Sources | |
|---|---|
| Domains | Deep_Learning, NLP |
| Last Updated | 2026-10-18 00:00 GMT |
Overview
PyTorch tensor computation library used for model weight conversion and low-level tensor manipulation in the FinGPT instruct-FinGPT subproject, providing the `torch` tensor API for checkpoint loading and weight permutation.
Description
This environment covers the core PyTorch dependency used by the LLaMA-to-HuggingFace weight conversion script. The converter loads Meta LLaMA checkpoint shards as `torch.Tensor` objects, permutes rotary embedding weights, concatenates/shards attention and feed-forward tensors, and writes them in HuggingFace format. This is distinct from Environment:AI4Finance_Foundation_FinGPT_PyTorch_CUDA which covers the full GPU training/inference stack; this page covers the base PyTorch library for tensor manipulation without CUDA requirements.
Usage
Use this environment for model weight conversion and any tensor manipulation that does not require GPU acceleration. Required by the LLaMA weight converter implementation.
System Requirements
| Category | Requirement | Notes |
|---|---|---|
| OS | Any | Cross-platform |
| Python | >= 3.8 | 3.10+ recommended |
| RAM | 16GB+ | Must hold full model weights in memory |
Dependencies
Python Packages
- `torch` >= 2.0.1
- `numpy` < 2 (see Environment:AI4Finance_Foundation_FinGPT_Python)
Credentials
No credentials required.
Quick Install
pip install "torch>=2.0.1"
Code Evidence
Tensor loading from `fingpt/FinGPT_RAG/instruct-FinGPT/convert_llama_weights_to_hf.py`:
import torch
loaded = torch.load(input_base_path + "/consolidated.00.pth", map_location="cpu")
Weight permutation:
def permute(w, n_heads, dim1, dim2):
return w.view(n_heads, dim1 // n_heads // 2, 2, dim2) \
.transpose(1, 2).reshape(dim1, dim2)
Common Errors
| Error Message | Cause | Solution |
|---|---|---|
| `RuntimeError: CUDA out of memory` | Loading on GPU | Use `map_location="cpu"` for conversion |
| `safetensors not installed` | Missing serialization lib | `pip install safetensors` |
Compatibility Notes
- CPU-only: Weight conversion runs on CPU; no CUDA needed.
- safetensors: The converter supports safetensors serialization for the output format.