Update README.md
Browse files
README.md
CHANGED
@@ -1,21 +1,184 @@
|
|
1 |
---
|
2 |
-
|
3 |
tags:
|
4 |
-
- text-generation
|
5 |
-
-
|
6 |
-
-
|
7 |
-
-
|
8 |
-
|
|
|
|
|
|
|
9 |
language:
|
10 |
-
- en
|
|
|
|
|
|
|
|
|
|
|
11 |
---
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
|
|
|
|
20 |
|
21 |
-
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
1 |
---
|
2 |
+
title: Linux Command Generator (Llama 3.2 1B)
|
3 |
tags:
|
4 |
+
- text-generation
|
5 |
+
- instruction-tuned
|
6 |
+
- llama
|
7 |
+
- unsloth
|
8 |
+
- lora
|
9 |
+
- linux
|
10 |
+
- command-generation
|
11 |
+
license: other
|
12 |
language:
|
13 |
+
- en
|
14 |
+
library_name: transformers
|
15 |
+
pipeline_tag: text-generation
|
16 |
+
datasets:
|
17 |
+
- custom
|
18 |
+
base_model: unsloth/Llama-3.2-1B-Instruct
|
19 |
---
|
20 |
|
21 |
+
### hrsvrn/linux-command-generator-llama3.2-1b
|
22 |
+
|
23 |
+
Natural language → Linux command. A compact Llama 3.2 1B Instruct model fine‑tuned (LoRA) to turn plain‑English requests into correct shell commands.
|
24 |
+
|
25 |
+
### TL;DR
|
26 |
+
- Base: `unsloth/Llama-3.2-1B-Instruct`
|
27 |
+
- Method: LoRA (r=16, alpha=16, dropout=0)
|
28 |
+
- Context: 2048 tokens
|
29 |
+
- Data: 8,669 pairs across 11 categories
|
30 |
+
- Use cases: quick command lookup, learning CLI, automation
|
31 |
+
|
32 |
+
## Run with Ollama (baby steps)
|
33 |
+
|
34 |
+
1) Install Ollama: see `https://ollama.com/download`.
|
35 |
+
|
36 |
+
2) Verify install:
|
37 |
+
```bash
|
38 |
+
ollama --version
|
39 |
+
```
|
40 |
+
|
41 |
+
3) Run the model interactively:
|
42 |
+
```bash
|
43 |
+
ollama run hrsvrn/linux-command-generator-llama3.2-1b
|
44 |
+
```
|
45 |
+
Then type a request, e.g.:
|
46 |
+
- "List all files in the current directory with detailed information"
|
47 |
+
- "Compress the file data.txt using bzip2"
|
48 |
+
- "Find all .py files in the current directory and subdirectories"
|
49 |
+
|
50 |
+
Press Ctrl+C to exit.
|
51 |
+
|
52 |
+
4) One‑off (non‑interactive):
|
53 |
+
```bash
|
54 |
+
ollama run hrsvrn/linux-command-generator-llama3.2-1b -p "Display the first 5 lines of access.log"
|
55 |
+
# Expected: head -n 5 access.log
|
56 |
+
```
|
57 |
+
|
58 |
+
5) Get command‑only answers (when needed):
|
59 |
+
```bash
|
60 |
+
ollama run hrsvrn/linux-command-generator-llama3.2-1b -p "Output only the command with no explanation. Show system information including kernel version"
|
61 |
+
# Expected: uname -a
|
62 |
+
```
|
63 |
+
|
64 |
+
|
65 |
+
### Use a local GGUF with Ollama (fallback)
|
66 |
+
If you have `model.gguf`, put it next to a `Modelfile`:
|
67 |
+
|
68 |
+
```
|
69 |
+
FROM ./model.gguf
|
70 |
+
PARAMETER temperature 0.2
|
71 |
+
PARAMETER top_p 0.9
|
72 |
+
PARAMETER num_ctx 2048
|
73 |
+
SYSTEM You are a Linux command generator. Output only the command with no explanation.
|
74 |
+
TEMPLATE {{ .Prompt }}
|
75 |
+
```
|
76 |
+
|
77 |
+
Create and run:
|
78 |
+
```bash
|
79 |
+
ollama create linux-cmd-gen -f Modelfile
|
80 |
+
ollama run linux-cmd-gen -p "Find all .py files recursively"
|
81 |
+
# Expected: find . -name "*.py"
|
82 |
+
```
|
83 |
+
|
84 |
+
## Other ways to use (optional)
|
85 |
+
|
86 |
+
### Transformers
|
87 |
+
```python
|
88 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
89 |
+
import torch
|
90 |
+
|
91 |
+
model_id = "hrsvrn/linux-command-generator-llama3.2-1b"
|
92 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
93 |
+
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else None)
|
94 |
+
|
95 |
+
def generate_command(description: str) -> str:
|
96 |
+
messages = [{"role": "user", "content": description}]
|
97 |
+
inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
98 |
+
if torch.cuda.is_available():
|
99 |
+
inputs = inputs.to(model.device)
|
100 |
+
model = model.to("cuda")
|
101 |
+
outputs = model.generate(input_ids=inputs, max_new_tokens=64)
|
102 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
103 |
+
|
104 |
+
print(generate_command("List all files in the current directory with detailed information"))
|
105 |
+
# -> ls -la
|
106 |
+
```
|
107 |
+
|
108 |
+
### Unsloth
|
109 |
+
```python
|
110 |
+
from unsloth import FastLanguageModel
|
111 |
+
|
112 |
+
model_id = "hrsvrn/linux-command-generator-llama3.2-1b"
|
113 |
+
model, tokenizer = FastLanguageModel.from_pretrained(model_name=model_id, max_seq_length=2048)
|
114 |
+
FastLanguageModel.for_inference(model)
|
115 |
+
|
116 |
+
msgs = [{"role": "user", "content": "Compress the file data.txt using bzip2"}]
|
117 |
+
inputs = tokenizer.apply_chat_template(msgs, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
118 |
+
output = model.generate(input_ids=inputs, max_new_tokens=32)
|
119 |
+
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
120 |
+
# -> bzip2 data.txt
|
121 |
+
```
|
122 |
+
|
123 |
+
## Example prompts → commands
|
124 |
+
- "Show system information including kernel version" → `uname -a`
|
125 |
+
- "Find all .py files in the current directory and subdirectories" → `find . -name "*.py"`
|
126 |
+
- "Display the first 5 lines of access.log" → `head -n 5 access.log`
|
127 |
+
- "Change permissions of script.sh to make it executable for owner" → `chmod +x script.sh`
|
128 |
+
- "Create a tar archive backup.tar containing all files in the documents folder" → `tar -cf backup.tar documents/`
|
129 |
+
|
130 |
+
## Dataset (overview)
|
131 |
+
8,669 input→command pairs across:
|
132 |
+
- Compression & Archiving: bzip2, gzip, tar, zip
|
133 |
+
- File & Directory: cd, cp, find, ls, mkdir, mv, pwd, rm, rmdir, touch
|
134 |
+
- Permissions & Ownership: chgrp, chmod, chown
|
135 |
+
- Viewing & Editing: cat, echo, head, less, tail, vim
|
136 |
+
- Networking: curl, dig, host, ifconfig, ip, netstat, ping, ssh, wget
|
137 |
+
- Package mgmt: apt, dpkg
|
138 |
+
- Process mgmt: kill, killall, nice, pkill, renice
|
139 |
+
- Search & Filter: awk, grep, locate, sed
|
140 |
+
- System info/monitoring: df, du, free, top, uname
|
141 |
+
- User/group: useradd, usermod, groupadd, passwd, sudo
|
142 |
+
- Misc/system control: cron, systemctl, tmux, screen, service
|
143 |
+
|
144 |
+
Format:
|
145 |
+
```json
|
146 |
+
{"input": "Describe what you want to do", "output": "linux_command_here"}
|
147 |
+
```
|
148 |
+
|
149 |
+
## Training details
|
150 |
+
- Base: `unsloth/Llama-3.2-1B-Instruct`
|
151 |
+
- LoRA on attention + MLP projections:
|
152 |
+
- r=16, lora_alpha=16, lora_dropout=0
|
153 |
+
- target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
|
154 |
+
- Max sequence length: 2048
|
155 |
+
- SFT on responses only (TRL SFTTrainer), Unsloth-optimized
|
156 |
+
- Example hparams: per‑device batch 2, grad accum 4, epochs 3, lr 2e‑4
|
157 |
+
- Reference: Tesla P100 16GB (~45 minutes), ~2.8GB VRAM (adapters)
|
158 |
+
|
159 |
+
## Safety and responsible use
|
160 |
+
- Always inspect commands before executing.
|
161 |
+
- Avoid destructive operations unless you fully understand consequences.
|
162 |
+
- For apps, add denylists and validations (e.g., block `rm -rf /`, `mkfs`, `dd`).
|
163 |
+
|
164 |
+
## Notes on GGUF
|
165 |
+
- Works with `llama.cpp` and Ollama.
|
166 |
+
- Typical memory (approx.): q4_k_s ~600MB, q4_k_m ~700MB, q8_0 ~1.1GB, f16 ~2.2GB.
|
167 |
+
|
168 |
+
## License
|
169 |
+
Derived from Meta Llama 3.2. Use must comply with the base model license. Check your deployment context for any additional constraints.
|
170 |
|
171 |
+
## Citation
|
172 |
+
```
|
173 |
+
@software{hrsvrn_linux_command_generator_llama32_1b,
|
174 |
+
author = {Harshvardhan Vatsa},
|
175 |
+
title = {Linux Command Generator (Llama 3.2 1B)},
|
176 |
+
year = {2025},
|
177 |
+
url = {https://huggingface.co/hrsvrn/linux-command-generator-llama3.2-1b}
|
178 |
+
}
|
179 |
+
```
|
180 |
|
181 |
+
## Acknowledgements
|
182 |
+
- Base: `unsloth/Llama-3.2-1B-Instruct`
|
183 |
+
- Libraries: `unsloth`, `transformers`, `trl`, `accelerate`, `bitsandbytes`
|
184 |
|
|