Text Generation
PEFT
Safetensors
Transformers
English
conversational
instruction-tuning
domain-adaptation
code
dotnet
csharp
lora
qlora
nf4
phi-4
arxiv:2106.09685
Instructions to use kotlarmilos/phi-4-mini-dotnet-runtime with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use kotlarmilos/phi-4-mini-dotnet-runtime with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("microsoft/Phi-4-mini-instruct") model = PeftModel.from_pretrained(base_model, "kotlarmilos/phi-4-mini-dotnet-runtime") - Transformers
How to use kotlarmilos/phi-4-mini-dotnet-runtime with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="kotlarmilos/phi-4-mini-dotnet-runtime") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("kotlarmilos/phi-4-mini-dotnet-runtime", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use kotlarmilos/phi-4-mini-dotnet-runtime with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "kotlarmilos/phi-4-mini-dotnet-runtime" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "kotlarmilos/phi-4-mini-dotnet-runtime", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/kotlarmilos/phi-4-mini-dotnet-runtime
- SGLang
How to use kotlarmilos/phi-4-mini-dotnet-runtime 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 "kotlarmilos/phi-4-mini-dotnet-runtime" \ --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": "kotlarmilos/phi-4-mini-dotnet-runtime", "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 "kotlarmilos/phi-4-mini-dotnet-runtime" \ --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": "kotlarmilos/phi-4-mini-dotnet-runtime", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use kotlarmilos/phi-4-mini-dotnet-runtime with Docker Model Runner:
docker model run hf.co/kotlarmilos/phi-4-mini-dotnet-runtime
File size: 4,478 Bytes
e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd e3d78b4 a0004cd d5031d4 a0004cd d5031d4 a0004cd f87c3d6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | ---
base_model: microsoft/Phi-4-mini-instruct
base_model_relation: adapter
library_name: peft
pipeline_tag: text-generation
license: mit
language:
- en
datasets:
- kotlarmilos/dotnet-runtime
tags:
- text-generation
- conversational
- instruction-tuning
- domain-adaptation
- code
- dotnet
- csharp
- lora
- qlora
- nf4
- phi-4
- peft
- transformers
- arxiv:2106.09685
inference: true
---
# Phi-4-mini fine-tuned on dotnet/runtime
This is a LoRA fine-tune of microsoft/Phi-4-mini-instruct adapted to the issue and pull request
history of the dotnet/runtime codebase. The goal is to move a small, efficient base model toward the
vocabulary, conventions, and recurring problems of one specific engineering domain so it reads and
responds in that domain's dialect.
## Where this fits
This is the first step in my applied post-training track. Here I change what a small model knows by
fitting it to a domain I understand. The next step, the [Gemma 3 reasoning
adapter](https://huggingface.co/kotlarmilos/gemma-3-1b-reasoning), changes how a model thinks rather than
what it knows. The step after that, the [Gemma 4
GlucoLens adapter](https://huggingface.co/kotlarmilos/gemma-4-e4b-glucolens), takes the same
instinct into a domain where the output is a structured rollout and the model has to refuse when it
is unsure. In parallel I built a transformer by hand in [gpt2-nano](https://huggingface.co/kotlarmilos/gpt2-nano)
to understand the layer underneath all of this.
## Model details
- Developed by Milos Kotlar
- Base model microsoft/Phi-4-mini-instruct
- Method LoRA with 4-bit NF4 quantization
- Language English
- License MIT
- Repository https://github.com/kotlarmilos/phi-4-mini-dotnet-runtime
- Demo https://huggingface.co/spaces/kotlarmilos/dotnet-runtime
## Intended use
The model is meant for assistance on the dotnet/runtime domain, reading issues and pull requests and
drafting responses in the terminology and style of that codebase. It is a research artifact, not a
production reviewer.
## Out of scope
The model is not built for factual retrieval, and it can produce plausible but wrong statements. It
is not a source of professional medical or legal advice, and it is not suitable for safety critical
systems. Do not use it to generate harmful or misleading content.
## How to load
```python
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel
BASE = "microsoft/Phi-4-mini-instruct"
ADAPTER = "kotlarmilos/phi-4-mini-dotnet-runtime"
bnb_config = BitsAndBytesConfig(
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=True,
bnb_4bit_compute_dtype=torch.bfloat16,
)
tokenizer = AutoTokenizer.from_pretrained(BASE, use_fast=True)
base = AutoModelForCausalLM.from_pretrained(
BASE, quantization_config=bnb_config, device_map="auto", trust_remote_code=True,
)
model = PeftModel.from_pretrained(base, ADAPTER)
def generate(prompt):
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
output = model.generate(
**inputs, max_new_tokens=256, do_sample=True, temperature=0.7,
pad_token_id=tokenizer.eos_token_id,
)
return tokenizer.decode(output[0], skip_special_tokens=True)
print(generate("Review the following code changes:"))
```
## Training
- Data. About 10,000 instruction and response pairs built from dotnet/runtime GitHub issues and pull
requests, published as the [dotnet-runtime dataset](https://huggingface.co/datasets/kotlarmilos/dotnet-runtime).
- Method. LoRA on the quantized base model, mixed precision.
- Quantization. 4-bit NF4 with BitsAndBytes.
**LoRA configuration**
| Parameter | Value |
|---|---|
| Rank r | 8 |
| Alpha | 16 |
| Dropout | 0.05 |
| Target modules | `qkv_proj`, `gate_up_proj` |
| Task type | CAUSAL_LM |
## Evaluation
I do not report a held-out benchmark score for this model. The effect of fine-tuning is a shift
toward the repository's terminology and issue framing relative to the base model on the same prompts.
A labeled evaluation split drawn from held-out issues is the natural next step. See the repository for
details.
## Source
- Repository https://github.com/kotlarmilos/phi-4-mini-dotnet-runtime
- Dataset https://huggingface.co/datasets/kotlarmilos/dotnet-runtime
- Demo https://huggingface.co/spaces/kotlarmilos/dotnet-runtime
- Writeup https://huggingface.co/blog/kotlarmilos/phi-4-mini-dotnet-runtime
|