Downloads · 30 days
0
iPwnds/finanalyst-qwen1.5b-final
finanalyst-qwen1.5b-final is a text generation model from iPwnds. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as apache-2.0.
A financial analyst LLM fine-tuned from Qwen2.5-3B-Instruct using QLoRA + ORPO (Odds Ratio Preference Optimisation) — a single-pass alignment method that combines supervised fine-tuning with preference learning, requi…
Downloads · 30 days
0
Access
Public
Updated Aug 9, 2026
Repo size
70.4 MB
Likes
0
Public
Click a slice to open those files.
.safetensors59 MB · 84%
From the Hugging Face model README
A financial analyst LLM fine-tuned from Qwen2.5-3B-Instruct using QLoRA + ORPO (Odds Ratio Preference Optimisation) — a single-pass alignment method that combines supervised fine-tuning with preference learning, requiring no separate reward model or reference model. This is the second-generation, upgraded successor to iPwnds/finanalyst-qwen1.5b: a larger base model, a wider LoRA adapter, and a preference-aligned training objective instead of plain SFT.
It runs fully locally — no API keys required. On Apple Silicon it uses MPS acceleration; on a machine with a CUDA GPU it uses that automatically; otherwise it falls back to CPU.
finanalyst-qwen1.5b-final is a parameter-efficient fine-tune of Qwen/Qwen2.5-3B-Instruct trained to behave like a senior sell-side analyst. The base model is loaded in 4-bit NF4 quantisation while LoRA adapter matrices are injected into all four attention projection layers (q_proj, k_proj, v_proj, o_proj) — double the rank and twice the target modules of v1. Only 0.4756% of the total parameters (14.75M out of 3.10B) were updated during training.
Rather than plain supervised fine-tuning, this model was trained with ORPO (Hong et al., 2024): each step runs two forward passes — one over a "chosen" (high-quality analyst) response, one over a "rejected" (generic, unfine-tuned base-model) response for the same prompt — and combines a standard SFT cross-entropy loss with an odds-ratio preference term that pushes the model to prefer the chosen style over the rejected one. No separate reference model or reward model is required.
Because the installed trl release (1.9.2) neither ships a standalone ORPOTrainer (removed after trl 1.0) nor exposes loss_type="orpo" on DPOTrainer, ORPO was implemented directly on top of transformers.Trainer for this run — a from-scratch, dependency-free reimplementation of the algorithm described in the paper.
The model is the generative core of the FinSight Bloomberg Terminal CLI — a Bloomberg-style terminal that uses this model for all text generation (stock deep-dives, market overviews, watchlist digests, and natural-language Q&A).
Qwen/Qwen2.5-3B-Instructnotebooks/FinAnalyst_Generative_Full.ipynbiPwnds/finanalyst-qwen1.5b (v1 — Qwen2.5-1.5B, SFT only)iPwnds/finsentiment-distilbert-finalThe model is designed to generate analyst-style financial commentary given a structured prompt containing live market data (price, fundamentals, news sentiment). It handles three task types out of the box:
The model plugs directly into the FinSight CLI via analysis/llm.py, which loads it with AutoPeftModelForCausalLM and merges the adapter at load time (merge_and_unload()), then exposes ask_llm() / ask_llm_stream() helper functions used throughout the application.
It can also be used as a drop-in instruction-following LLM for any financial NLP pipeline that needs analyst-style prose generation, or as a base for further preference-alignment experiments given its ORPO training lineage.
Qwen2.5-3B-Instruct, may carry biases inherited from its pre-training corpus.Always supply the model with current, factual market data in the prompt (price, fundamentals, news). Do not rely on the model's parametric knowledge for specific numerical claims. All output should be reviewed by a qualified professional before informing any financial decision.
from peft import AutoPeftModelForCausalLM
from transformers import AutoTokenizer, pipeline
import torch
MODEL = "iPwnds/finanalyst-qwen1.5b-final"
# Detect device
if torch.backends.mps.is_available():
device_map, dtype = {"": "mps"}, torch.float16
elif torch.cuda.is_available():
device_map, dtype = "auto", torch.float16
else:
device_map, dtype = {"": "cpu"}, torch.float32
# Load base model + LoRA adapter, then merge for faster inference
model = AutoPeftModelForCausalLM.from_pretrained(
MODEL,
torch_dtype=dtype,
device_map=device_map,
).merge_and_unload()
tokenizer = AutoTokenizer.from_pretrained(MODEL)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
messages = [
{"role": "system", "content": "You are a senior equity analyst. Be concise and data-driven."},
{"role": "user", "content": "Is NVDA overbought at current levels given its AI growth story?"},
]
result = pipe(messages, max_new_tokens=512, temperature=0.3, do_sample=True)
print(result[0]["generated_text"][-1]["content"])
The model uses the ChatML chat template (<|im_start|> / <|im_end|>) inherited from Qwen2.5-3B-Instruct. Always pass messages as a list of role/content dicts rather than raw strings.
Base instruction data was generated programmatically by scripts/generate_training_data.py, which fetches live fundamentals, price history, and news via yfinance, constructs structured analyst prompts, and calls an LLM to generate reference responses. The dataset contains 156 instruction examples:
| Task type | Count | Unique tickers |
|---|---|---|
stock_analysis | 51 | 51 |
ask (free-form Q&A) | 104 | 52 |
market_overview | 1 | 1 |
For ORPO, preference pairs were built from the first 100 examples:
chosen — the original high-quality reference response from the instruction dataset.rejected — a response to the same prompt generated by the unfine-tuned Qwen2.5-3B-Instruct base model (temperature 0.8, top-p 0.9, max 256 new tokens).Mean chosen length: 334 words. Mean rejected length: 113 words — the base model's zero-shot responses are noticeably shorter and less structured than the curated analyst outputs, which is the contrast ORPO optimises against.
The 90/10 train/test split (seed=42) gives 90 training pairs and 10 evaluation pairs.
Fine-tuning was performed in Google Colab on a T4 GPU (15 GB VRAM) using a custom ORPOTrainer subclassing transformers.Trainer (see Model Description above for why trl's trainer wasn't used).
Prompt and response are tokenised separately so the prompt/response boundary is exact, then concatenated: [prompt_ids] + [response_ids] + [eos], truncated/padded to a fixed length. Labels are set to -100 over the prompt span so only the response contributes to the loss.
Sequences were truncated/padded to a maximum of 1024 tokens.
| Hyperparameter | Value |
|---|---|
| Base model | Qwen/Qwen2.5-3B-Instruct |
| Quantisation | 4-bit NF4 + double quantisation |
| Compute dtype | float16 |
LoRA rank (r) | 32 |
| LoRA alpha | 64 |
| LoRA target modules | q_proj, k_proj, v_proj, o_proj |
| LoRA dropout | 0.05 |
| Trainable parameters | 14,745,600 / 3,100,684,288 (0.4756%) |
| ORPO beta | 0.1 |
| Epochs | 3 |
| Per-device batch size | 1 |
| Gradient accumulation steps | 8 (effective batch size: 8) |
| Learning rate | 8e-6 |
| Max sequence length | 1024 tokens |
| Mixed precision | None (fp16=False, bf16=False) |
| Gradient checkpointing | Enabled |
| Optimizer | AdamW (default) |
Note on evaluation: the base
Trainer.prediction_steplooks for a top-level"labels"key to decide whether to route through a customcompute_loss; since the ORPO collator instead emitschosen_labels/rejected_labels,prediction_stepwas overridden to always call the custom ORPO loss during evaluation.
| Training time | ~15–20 minutes (T4 GPU, Google Colab) |
| Total steps | 36 (3 epochs × 12 steps) |
| Adapter size (pushed to Hub) | 59.0 MB |
| Base model size (downloaded at inference) | ~6 GB |
A 10% held-out split (10 preference pairs, seed=42) from the same generated ORPO dataset.
Evaluation loss — the combined ORPO objective (SFT cross-entropy + β × odds-ratio loss, β=0.1) computed on held-out chosen/rejected pairs.
| Metric | Value |
|---|---|
| Final ORPO eval loss | 1.0125 |
| v1 SFT eval loss (for reference) | 1.4721 |
These two numbers are not directly comparable — v1's 1.4721 is a pure SFT cross-entropy loss, while 1.0125 is the combined ORPO objective (SFT + odds-ratio term). Both are reported for context, not as an apples-to-apples benchmark.
The model learns the instruction-following format and analyst prose style, and the ORPO odds-ratio term separates chosen from rejected response likelihoods as intended. As with v1, the primary limitation is dataset size — 90 training pairs is small for preference optimisation, and broader coverage of tickers, task types, and market conditions (plus preference pairs sourced from a genuinely weaker/different model rather than self-play) would likely improve robustness.
Training was performed on a Google Colab T4 GPU for approximately 15–20 minutes. Estimated carbon emissions are negligible at this scale.
bitsandbytes, with low-rank adapter matrices (LoRA) injected into q_proj, k_proj, v_proj, and o_proj of each attention block<|im_start|> / <|im_end|>)| Package | Role |
|---|---|
transformers | Model loading, tokenisation, pipeline, base Trainer (custom ORPO loss built on top) |
peft | LoRA adapter injection and AutoPeftModelForCausalLM |
bitsandbytes ≥ 0.46.1 | 4-bit NF4 quantisation |
accelerate | Device placement and distributed training |
datasets | Preference-pair dataset formatting and train/test split |
Florian Braun (@iPwnds)