Text Generation
Transformers
Safetensors
English
qwen2
financial-modeling
fintech
quant
python
code-generation
reasoning
chain-of-thought
execution-verified
unsloth
conversational
text-generation-inference
Instructions to use coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full with Transformers:
# 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full
- SGLang
How to use coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio
How to use coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full", max_seq_length=2048, ) - Docker Model Runner
How to use coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full with Docker Model Runner:
docker model run hf.co/coslinedev/Qwen2.5-3B-FinCode-Reasoning-Full
| license: apache-2.0 | |
| language: | |
| - en | |
| pipeline_tag: text-generation | |
| tags: | |
| - financial-modeling | |
| - fintech | |
| - quant | |
| - python | |
| - code-generation | |
| - reasoning | |
| - chain-of-thought | |
| - execution-verified | |
| - unsloth | |
| base_model: Qwen/Qwen2.5-3B-Instruct | |
| pretty_name: FinCode-Reasoning-3B | |
| library_name: transformers | |
| # π FinCode-Reasoning-3B | |
| [](https://opensource.org/licenses/Apache-2.0) | |
| [](https://huggingface.co/datasets/coslinedev/FinCode-Reasoning-v1) | |
| [](https://github.com/unslothai/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](https://github.com/unslothai/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](https://0f0743a77ec537bffa.gradio.live/) | Instant interactive browser interface (Active for 72h). | | |
| | π» **Google Colab Notebook** | [](https://colab.research.google.com/drive/11TXF91zmoPnDkSRcepBJRR8OZINPMoGj?usp=sharing) | 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%).* | |
| ```text | |
| β 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. |