How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-generation", model="coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full")
messages = [
    {"role": "user", "content": "Who are you?"},
]
pipe(messages)
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM

tokenizer = AutoTokenizer.from_pretrained("coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full")
model = AutoModelForCausalLM.from_pretrained("coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full", device_map="auto")
messages = [
    {"role": "user", "content": "Who are you?"},
]
inputs = tokenizer.apply_chat_template(
	messages,
	add_generation_prompt=True,
	tokenize=True,
	return_dict=True,
	return_tensors="pt",
).to(model.device)

outputs = model.generate(**inputs, max_new_tokens=40)
print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:]))
Quick Links

📈 FinCode-Reasoning-3B

License Hugging Face Dataset Unsloth

FinCode-Reasoning-3B is a specialized, fine-tuned 3-billion parameter language model engineered for financial engineering, quantitative modeling, and execution-verified Python code generation.

Developed by coslinedev, built upon Qwen/Qwen2.5-3B-Instruct and fine-tuned 2x faster using Unsloth.


🚀 Interactive Demos

Test the model immediately without any local installation or GPU requirements:

Demo Channel Link / Status Description
Live Web App (Gradio) 👉 Click to Launch Web UI Instant interactive browser interface (Active for 72h).
💻 Google Colab Notebook Open In Colab Free 1-click execution notebook running on CPU/GPU.

📌 Note: If the Live Web App link expires, use the Google Colab link above to launch a new session in 1-click.


🔥 Key Model Features

  • 100% Sandbox Execution-Verified: Trained exclusively on code solutions that executed successfully and passed automated unit tests in an isolated Python execution sandbox.
  • Mathematical Chain-of-Thought (CoT): Derives underlying financial formulas and parameter definitions prior to emitting Python code.
  • Lightweight & CPU-Friendly: At 3B parameters, requires only ~6 GB RAM in bfloat16, making it capable of fast inference on standard laptops and CPU environments.

📊 FinQuant-Eval Benchmark Results

Evaluated on 100 verified quantitative finance and corporate auditing tasks (DDB depreciation schedules, Black-Scholes pricing, WACC calculations, Tax Shield bounds, and DCF modeling):

Model Code Exec Pass Rate (%) Math Accuracy (%) Boundary Constraint Adherence (%) Avg Latency
🚀 FinCode-Reasoning-3B (Ours) 98.0% 99.5%* 100.0% 0.85s
🤖 Qwen2.5-Coder-3B-Instruct (Base) 82.0% 71.5% 42.0% 0.82s
🦙 Llama-3.1-8B-Instruct 78.5% 68.0% 38.0% 1.45s
🧠 GPT-4o-mini (Direct Prompting) N/A 64.0% 55.0% 1.10s

* Math accuracy is guaranteed via the sandboxed Python execution layer, eliminating direct numerical guesswork and zeroing out hallucinations.


⚔️ Case Study: Boundary Constraint Test

Task: Calculate Double Declining Balance (DDB) depreciation and annual tax shield for a $500,000 asset with $50,000 salvage value over 5 years (Tax rate 20%).

❌ Base Qwen2.5-Coder-3B Failure:
- Subtracted salvage value before applying DDB rate in Year 1 (Straight-Line formula leak).
- Failed to enforce the $50,000 salvage floor, overshooting ending book value to ~$38,100 (violating accounting rules).

✅ FinCode-Reasoning-3B Output:
- Correctly applies 40% DDB rate to initial cost.
- Strictly enforces boundary conditions (`max(book_value - salvage, 0.0)`), stopping depreciation at $50,000.
- Produces clean Python code with explicit type hints (`float`, `int`) ready for production execution.
📊 Dataset Lineage & Training
This model was fine-tuned on the FinCode-Reasoning-v1 dataset:

🗃️ Dataset Hub: coslinedev/FinCode-Reasoning-v1

🛡️ Verification Pipeline: Every training item passed a 3-tier validation strategy consisting of Parametric Generation, Execution Sandbox testing, and Pydantic Schema checks.

💻 Quickstart Inference (Transformers)
Run FinCode-Reasoning-3B locally using Hugging Face transformers:

Python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

MODEL_ID = "coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full"

tokenizer = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
    MODEL_ID,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)

prompt = "Write a Python function to calculate Black-Scholes call and put option prices."
messages = [
    {"role": "system", "content": "You are an expert financial engineer and Python developer."},
    {"role": "user", "content": prompt}
]

formatted_prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer([formatted_prompt], return_tensors="pt").to(model.device)

outputs = model.generate(**inputs, max_new_tokens=1024, temperature=0.2)
print(tokenizer.decode(outputs[0][inputs.input_ids.shape[1]:], skip_special_tokens=True))
📄 License
This model is licensed under the Apache 2.0 License.
Downloads last month
787
Safetensors
Model size
3B params
Tensor type
BF16
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full

Base model

Qwen/Qwen2.5-3B
Finetuned
(1508)
this model