Skip to content

papers & experiments

Research

Independent research on adaptive attention, CPU-efficient LLM inference, and budgeted code maps for local Gemma agents.

Zenodo, 2026 · Muhammad Maroof

QuerySmith: Fine-Tuning Phi-4-mini for Text-to-SQL Generation with CPU-Efficient Partial-Residual Quantization

LLMs fine-tuned for text-to-SQL are usually evaluated and deployed assuming GPU inference, which limits use in on-premise or resource-constrained settings. This work (1) fine-tunes Phi-4-mini-instruct (3.8B parameters) with QLoRA (rank 16, alpha 32, dropout 0.05) on the QuerySmith-Spider-Bird dataset, and (2) introduces a progression of CPU quantization strategies, culminating in a partial-residual quantization scheme that keeps accuracy close to FP32 while running on CPU-only hardware.

Key contributions

  • Compact text-to-SQL model fine-tuned on a Spider/BIRD-derived dataset
  • Partial-residual quantization: aggressive quantization of a subset of transformer blocks plus low-rank SVD error correction; recovers 92.2% of the accuracy lost by naive INT4 (0.707 vs 0.636)
  • llama.cpp / GGUF deployment adds a further 65.3% latency reduction; best throughput at 8 to 12 CPU threads on a 14-core Intel Core i5 (16 GB RAM)
  • Post-optimization fine-tuning exceeds the FP32 baseline (0.743 vs 0.713) while running 6.6x faster and 4.2x smaller
ConfigAccuracyms/tokenSize (MB)
FP32 (baseline)0.713148.014890.5
FP160.709121.47445.0
INT80.68289.13721.8
INT4 (naive)0.63671.11859.9
Partial-Residual0.70779.33511.2
Partial-Residual + llama.cpp Q4_00.70727.5n/a
+ post-optimization fine-tune0.74322.33511.2
ms per token (lower is better)
FP32
148
Final
22.3

6.6x faster, 4.2x smaller!

Limitations: Residual rank fixed at 8; 200-example evaluation set.

@misc{maroof2026querysmith,
  title={QuerySmith: Fine-Tuning Phi-4-mini for Text-to-SQL Generation with CPU-Efficient Partial-Residual Quantization},
  author={Maroof, Muhammad},
  year={2026},
  publisher={Zenodo},
  url={https://zenodo.org/records/23000490}
}

Zenodo preprint, May 2026 · Muhammad Maroof

An Empirical Study of Adaptive Activation Attention

This paper introduces Adaptive Activation Attention (A³), a method that replaces the fixed softmax in Transformer attention with a learnable, input-dependent activation. We prove that A³ always produces a valid probability distribution and that, with default initialization, it exactly recovers standard softmax attention at the start of training.

Key contributions

  • Proposes A³: a learnable attention activation that adapts per input using a gated score matrix and a learned additive bias
  • Proves validity: outputs are non-negative and sum to 1 for any parameter values
  • Proves softmax recovery: default initialization behaves exactly like standard softmax attention
  • Empirically studies the behavior and potential of adaptive activation attention in Transformer models
@misc{maroof2026empirical,
  title={An Empirical Study of Adaptive Activation Attention},
  author={Maroof, Muhammad},
  year={2026},
  month={may},
  howpublished={Zenodo preprint, version 1.0},
  publisher={Zenodo},
  url={https://zenodo.org/records/20364414}
}

Zenodo preprint, version 1 · 3 Nov 2026 · Muhammad Maroof

AST-Compressed Code Graphs for Gemma 4 Agents: What a Small Local Model Gains from a Budgeted Repository Map

Local coding agents have tight context budgets, making whole-repository prompts impractical. This work builds a tree-sitter map of Python symbol signatures, ranks symbols against each issue and packs the best entries into a strict token budget. On 150 SWE-bench Lite issues with 4-bit Gemma 4 E4B on one NVIDIA T4, the signature-only map achieved 0.527 file Acc@1 at 2,048 tokens, versus 0.380 for function-snippet RAG and 0.280 for raw top-k files. Adding call edges and control-flow counts did not improve the results; the study also measures prefill memory and documents its limits.

Key contributions

  • Builds an incremental Python repository map from tree-sitter AST symbol signatures, source ranges and related metadata.
  • Uses issue-aware ranking and score-per-token selection to keep the repository context within a hard budget.
  • At 2,048 tokens, the signature map reaches 0.527 File Acc@1 (95% CI 0.447–0.607) and 0.647 File Acc@3 on 150 test issues.
  • File Acc@1 exceeds function-snippet RAG (0.380), raw top-k files (0.280) and BM25 file ranking (0.267); function Acc@1 is comparable to snippet RAG (0.235 vs 0.227).
  • Adding call edges and control-flow counts lowers the measured file and function accuracy versus signatures alone, a useful negative result for fixed context budgets.
  • Chunked prefill with last-token logits allowed an 8,192-token prefill on a T4; this measures prefill only, not answer quality or decoding at that length.

Limitations: One model, one quantization and one run; 150 test issues with wider uncertainty in the 60-instance ablations. The task is issue localization, not patch generation. The 8k-token result measures prefill only, and the MCP/tool agent path was not evaluated with Gemma 4.

@misc{maroof2026astcompressed,
  title={AST-Compressed Code Graphs for Gemma 4 Agents: What a Small Local Model Gains from a Budgeted Repository Map},
  author={Maroof, Muhammad},
  year={2026},
  publisher={Zenodo},
  url={https://zenodo.org/records/23927442}
}
M

drawing ideas into systems...