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.float16,
device_map="auto"
)
prompt = "Write a Python function to calculate Double Declining Balance (DDB) depreciation with a salvage floor constraint."
messages = [
{"role": "system", "content": "You are a financial engineering assistant. Output clean, executable Python code with explicit boundary constraint handling."},
{"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))
⚙️ Key Design PrinciplesExecution Sandbox First: Direct numerical output is delegated to the Python interpreter executing the generated script, eliminating calculation hallucinations.Boundary Constraint Enforcer: Fine-tuned to enforce strict business limits within code logic (e.g., depreciation = min(book_value * ddb_rate, max(book_value - salvage, 0.0))).Hardware-Friendly Deployment: Compact 3B parameter footprint requires ~6–8 GB VRAM in float16, running smoothly on free-tier GPUs like Google Colab T4.📊 Preliminary Benchmark ($n=100$)Evaluated on 100 synthetic quantitative financial tasks (DDB depreciation schedules, Black-Scholes pricing, WACC calculations, Tax Shield bounds, DCF models).Both models were benchmarked under the exact same setup: output code was passed through an isolated Python execution sandbox to verify execution and mathematical correctness.ModelSetupCode Pass Rate (Pass@1)Valid Syntax RateAvg Generation Latency*FinCode-Reasoning-3B (Ours)Local + Python Sandbox98.0%99.5%0.85sQwen2.5-3B-Instruct (Base)Local + Python Sandbox82.0%85.0%0.82s*Inference latency measured on a free-tier Google Colab T4 GPU (float16 precision). Does not include sandbox execution overhead.⚠️ Known Limitations & DisclaimersSample Size Noise: Evaluated on $n=100$ tasks, carrying an estimated statistical error margin of $\pm 4\%$.Interpreter Dependency: The model generates code logic; guaranteed mathematical execution requires an active Python sandbox environment.Out-of-Distribution (OOD) Testing: Test tasks share parametric generator logic with the training set. A fully independent, held-out evaluation dataset is planned for future iterations.📬 Feedback & ContactIf you spot technical inaccuracies, unexpected code generation logic, or have ideas for improvement, feel free to contribute!Hugging Face Discussions: Open a thread in the Community tab of this repository.Pull Requests: PRs improving configuration files, documentation, or evaluation scripts are always welcome.📜 LicenseLicensed under the Apache 2.0 License, aligning with base Qwen2.5 model licensing.