Introduction
Large Language Models (LLMs) have demonstrated remarkable proficiency in mainstream programming languages like Python and Java. However, their performance degrades significantly when applied to niche, low-resource domains. This report details a collaboration between researchers at Morgan Stanley and Prime Intellect to specialize the Qwen-2.5 model series for the Q programming language—a terse, array-oriented language primarily used in quantitative finance.
The challenge of adapting models to Q is twofold: a severe lack of high-quality open-source training data and the absence of standardized evaluation benchmarks. To overcome these hurdles, the authors developed a "full-stack" training pipeline that transforms general-purpose models into domain experts.
The Full-Stack Methodology
The adaptation process follows a four-stage pipeline designed to progressively build domain expertise:
- Model-in-the-Loop Bootstrapping: Using Qwen-2.5-32B-Instruct, the researchers translated LeetCode problems from Python to Q. A key innovation was the strict separation of solution generation from test harness generation to prevent "reward hacking."
- Domain-Adaptive Pretraining: The models underwent next-token prediction on a curated 1.6-million-token corpus of Q code and documentation, establishing a foundational understanding of syntax and idioms.
- Supervised Fine-Tuning (SFT): Multi-task training (e.g., Python-to-Q, Q-to-Python) aligned the models with specific functional requirements.
- Reinforcement Learning (RL): Utilizing Group Relative Policy Optimization (GRPO), the models were refined further. The researchers explored "reasoning" variants where models articulate their logic before generating code.
Datasets and Benchmarking
A critical contribution of this work is the Q-LeetCode benchmark. It consists of 678 problems (542 for training, 136 for testing), each featuring natural language descriptions, Python reference solutions, and Q-specific test harnesses.
The pretraining data was sourced from a "Permissive Q Corpus," comprising approximately 5 million characters of code scraped from GitHub (filtered for MIT/Apache 2.0 licenses) and official KDB+ documentation. Data quality was prioritized through an LLM-as-a-judge filtering process.
Key Results
The full-stack approach yielded significant performance gains, particularly at higher parameter scales. The Qwen-2.5-32B model achieved a 59% pass@1 accuracy on the Q-LeetCode benchmark, vastly outperforming established frontier models.
Key Insights:
- The 14B Threshold: Genuine progress in domain adaptation was most evident at the 14B parameter scale and above. Smaller models (1.5B and 3B) showed limited capacity to benefit from complex RL.
- RL and Reasoning: For the 32B model, RL—especially when combined with explicit reasoning chains—provided a substantial boost over SFT alone.
- Pretraining "Jumps": Introducing a large-scale pretraining phase was essential to overcome stagnation in the bootstrapping process, providing the necessary "intelligence" for models to solve more complex problems.
Limitations and Future Directions
While the results are promising, the authors acknowledge that the Q-LeetCode benchmark is inherently "Pythonic." The resulting code often mirrors Python's procedural logic rather than the high-performance, database-centric style typical of real-world Q/KDB+ development.
Future efforts will focus on creating benchmarks that better reflect practical financial use cases and applying this "full-stack" blueprint to other specialized scientific and corporate domains.
Summary updated