Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:AI4Finance Foundation FinGPT HuggingFace Hub

From Leeroopedia
Knowledge Sources
Domains Deep_Learning, Infrastructure
Last Updated 2026-10-18 00:00 GMT

Overview

HuggingFace Hub access for downloading pretrained models, LoRA adapters, and datasets hosted on `huggingface.co`.

Description

This environment provides authenticated access to the HuggingFace Hub, which hosts the base models (e.g., `meta-llama/Llama-2-7b-chat-hf`), LoRA adapter weights (e.g., `FinGPT/fingpt-forecaster_dow30_llama2-7b_lora`), and benchmark datasets (e.g., `FinGPT/fingpt-*`). Gated models such as Meta's Llama-2 require an access token. The Hub timeout is explicitly increased to handle slow connections and large file downloads.

Usage

Use this environment when loading models or datasets from the HuggingFace Hub (`from_remote=True`) or when accessing gated repositories. Required by the Forecaster inference app, benchmark training/evaluation, and any `AutoModelForCausalLM.from_pretrained` call with remote model names.

System Requirements

Category Requirement Notes
OS Any (Linux/Mac/Windows) Platform-independent
Hardware Internet connection Broadband for multi-GB model downloads
Disk 10-50GB Per model checkpoint (~13GB for 7B, ~26GB for 13B)

Dependencies

Python Packages

  • `huggingface-hub` >= 0.16.4
  • `transformers` >= 4.32.0
  • `datasets` >= 2.14.5
  • `safetensors` >= 0.3.3

Credentials

The following environment variables must be set:

  • `HF_TOKEN`: HuggingFace API token (required for gated models like Llama-2). Must not be empty or the app raises `ValueError`.

Quick Install

pip install huggingface-hub>=0.16.4 transformers>=4.32.0 datasets>=2.14.5 safetensors>=0.3.3

Code Evidence

Token validation and error raising from `fingpt/FinGPT_Forecaster/app.py:22-28`:

access_token = os.environ.get("HF_TOKEN", "")
finnhub_api_key = os.environ.get("FINNHUB_API_KEY", "")

if not access_token:
    raise ValueError("HF_TOKEN environment variable is not set. Please set it in your Space secrets.")

Hub timeout increase from `fingpt/FinGPT_Forecaster/app.py:19-20`:

os.environ.setdefault("HF_HUB_TIMEOUT", "120")

Authenticated model loading from `fingpt/FinGPT_Forecaster/app.py:32-39`:

base_model = AutoModelForCausalLM.from_pretrained(
    'meta-llama/Llama-2-7b-chat-hf',
    token=access_token,
    trust_remote_code=True,
    device_map="auto",
    torch_dtype=torch.float16,
    offload_folder="offload/"
)

Common Errors

Error Message Cause Solution
`HF_TOKEN environment variable is not set` Missing or empty token Set `HF_TOKEN` in environment or HuggingFace Space secrets
`Repository not found` Gated model without token Accept model license on HuggingFace and set `HF_TOKEN`
`ConnectionError / ReadTimeout` Slow network or large files Hub timeout auto-set to 120s via `HF_HUB_TIMEOUT`

Compatibility Notes

  • Gated models: Llama-2, Llama-3 require accepted license terms on HuggingFace plus a valid `HF_TOKEN`.
  • Local fallback: Set `from_remote=False` to load from `base_models/` local directory instead of Hub.
  • HuggingFace Spaces: Use Space secrets (not environment files) for `HF_TOKEN` in deployed apps.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment