File size: 3,979 Bytes
19f387d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a5485ca
 
 
 
 
 
391d987
a5485ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391d987
 
 
a5485ca
391d987
a5485ca
391d987
a5485ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
391d987
a5485ca
391d987
a5485ca
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
language:
- ru
- en
license: apache-2.0
tags:
- linux
- shell
- qwen2
- unsloth
- gguf
base_model: Qwen/Qwen2.5-3B-Instruct
pipeline_tag: text-generation
---


# Qwen2.5-3B Linux Assistant

A fine-tuned version of [Qwen2.5-3B-Instruct](https://huggingface.co/Qwen/Qwen2.5-3B-Instruct) trained to act as a Linux/Shell command assistant. Given a natural language description, the model outputs the correct shell command.

Supports both **Russian** and **English** input.

---

## Model Details

| Property | Value |
|---|---|
| Base model | Qwen2.5-3B-Instruct |
| Fine-tuning method | QLoRA (LoRA r=16, alpha=16) |
| Training steps | ~1700 |
| Epochs | 3 |
| Final loss | ~0.28 |
| Dataset size | ~4500 examples |
| Languages | Russian, English |
| Framework | Unsloth + TRL |

---

## Usage

### Ollama (recommended)
```bash
ollama run hf.co/NickIBrody/qwen-linux-gguf
```

### llama.cpp
```bash
llama-cli -hf NickIBrody/qwen-linux-gguf --jinja
```

### Python (transformers)
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

model_id = "NickIBrody/qwen-linux"
tok = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16, device_map="auto")

messages = [
    {"role": "system", "content": "You are a Linux assistant. Reply only with the shell command, no explanations."},
    {"role": "user", "content": "show top 5 processes by memory usage"},
]
inp = tok.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt").to(model.device)
out = model.generate(inp, max_new_tokens=128, temperature=0.3)
print(tok.decode(out[0][inp.shape[1]:], skip_special_tokens=True))
```

---

## Examples

| Input | Output |
|---|---|
| показажи топ 5 процессов по памяти | `ps aux --sort=-%mem \| head -n 5` |
| где я нахожусь в терминале | `pwd` |
| compress file data.txt with bzip2 | `bzip2 data.txt` |
| show disk usage in human readable format | `df -h` |
| find all .log files modified in last 7 days | `find / -name "*.log" -mtime -7` |
| kill process by name nginx | `pkill nginx` |
| show open ports | `ss -tulnp` |

---

## Dataset

Training data: [NickIBrody/linux-commands-ru-en](https://huggingface.co/datasets/NickIBrody/linux-commands-ru-en)

~4500 shell command examples in Russian and English, covering:
- File system navigation and management
- Process management
- Networking
- Archive and compression
- System monitoring
- Package management

---

## Training Code

```python
from unsloth import FastLanguageModel
from unsloth.chat_templates import get_chat_template
from datasets import load_dataset
from trl import SFTTrainer
from transformers import TrainingArguments

model, tok = FastLanguageModel.from_pretrained(
    "unsloth/Qwen2.5-3B-Instruct-bnb-4bit",
    max_seq_length=2048,
    load_in_4bit=True
)

model = FastLanguageModel.get_peft_model(
    model, r=16, lora_alpha=16,
    target_modules=["q_proj","k_proj","v_proj","o_proj","gate_proj","up_proj","down_proj"]
)

tok = get_chat_template(tok, chat_template="qwen-2.5")

ds = load_dataset("NickIBrody/linux-commands-ru-en", split="train")
ds = ds.map(lambda x: {"text": tok.apply_chat_template(x["messages"], tokenize=False)})

SFTTrainer(
    model=model,
    tokenizer=tok,
    train_dataset=ds,
    dataset_text_field="text",
    max_seq_length=2048,
    args=TrainingArguments(
        per_device_train_batch_size=2,
        gradient_accumulation_steps=4,
        num_train_epochs=3,
        learning_rate=2e-4,
        fp16=True,
        logging_steps=10,
        output_dir="out",
        optim="adamw_8bit"
    )
).train()

model.save_pretrained_gguf("qwen-linux", tok, quantization_method="q4_k_m")
```

---

## Limitations

- Designed for shell commands only, not general conversation
- May struggle with highly complex multi-step scripts
- Best results with clear, specific prompts

---

## License

Apache 2.0