初始化项目,由ModelHub XC社区提供模型
Model: mecha-org/linux-command-generator-llama3.2-1b Source: Original Platform
This commit is contained in:
38
.gitattributes
vendored
Normal file
38
.gitattributes
vendored
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
*.7z filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.arrow filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bin filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ftz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.gz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.h5 filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.joblib filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.model filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npy filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.npz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.onnx filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.ot filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.parquet filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pb filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pickle filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pkl filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pt filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.pth filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.rar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
||||||
|
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tar filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tflite filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.tgz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.wasm filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.xz filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zip filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*.zst filter=lfs diff=lfs merge=lfs -text
|
||||||
|
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
||||||
|
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
||||||
|
unsloth.F16.gguf filter=lfs diff=lfs merge=lfs -text
|
||||||
|
unsloth.Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
|
||||||
57
Modelfile
Normal file
57
Modelfile
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
FROM /kaggle/working/hrsvrn/linux-command-generator-llama3.1-1b/unsloth.F16.gguf
|
||||||
|
TEMPLATE """{{ if .Messages }}
|
||||||
|
{{- if or .System .Tools }}<|start_header_id|>system<|end_header_id|>
|
||||||
|
{{- if .System }}
|
||||||
|
|
||||||
|
{{ .System }}
|
||||||
|
{{- end }}
|
||||||
|
{{- if .Tools }}
|
||||||
|
|
||||||
|
You are a helpful assistant with tool calling capabilities. When you receive a tool call response, use the output to format an answer to the original use question.
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}<|eot_id|>
|
||||||
|
{{- range $i, $_ := .Messages }}
|
||||||
|
{{- $last := eq (len (slice $.Messages $i)) 1 }}
|
||||||
|
{{- if eq .Role "user" }}<|start_header_id|>user<|end_header_id|>
|
||||||
|
{{- if and $.Tools $last }}
|
||||||
|
|
||||||
|
Given the following functions, please respond with a JSON for a function call with its proper arguments that best answers the given prompt.
|
||||||
|
|
||||||
|
Respond in the format {"name": function name, "parameters": dictionary of argument name and its value}. Do not use variables.
|
||||||
|
|
||||||
|
{{ $.Tools }}
|
||||||
|
{{- end }}
|
||||||
|
|
||||||
|
{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>
|
||||||
|
|
||||||
|
{{ end }}
|
||||||
|
{{- else if eq .Role "assistant" }}<|start_header_id|>assistant<|end_header_id|>
|
||||||
|
{{- if .ToolCalls }}
|
||||||
|
|
||||||
|
{{- range .ToolCalls }}{"name": "{{ .Function.Name }}", "parameters": {{ .Function.Arguments }}}{{ end }}
|
||||||
|
{{- else }}
|
||||||
|
|
||||||
|
{{ .Content }}{{ if not $last }}<|eot_id|>{{ end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else if eq .Role "tool" }}<|start_header_id|>ipython<|end_header_id|>
|
||||||
|
|
||||||
|
{{ .Content }}<|eot_id|>{{ if $last }}<|start_header_id|>assistant<|end_header_id|>
|
||||||
|
|
||||||
|
{{ end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- end }}
|
||||||
|
{{- else }}
|
||||||
|
{{- if .System }}<|start_header_id|>system<|end_header_id|>
|
||||||
|
|
||||||
|
{{ .System }}<|eot_id|>{{ end }}{{ if .Prompt }}<|start_header_id|>user<|end_header_id|>
|
||||||
|
|
||||||
|
{{ .Prompt }}<|eot_id|>{{ end }}<|start_header_id|>assistant<|end_header_id|>
|
||||||
|
|
||||||
|
{{ end }}{{ .Response }}{{ if .Response }}<|eot_id|>{{ end }}"""
|
||||||
|
PARAMETER stop "<|start_header_id|>"
|
||||||
|
PARAMETER stop "<|end_header_id|>"
|
||||||
|
PARAMETER stop "<|eot_id|>"
|
||||||
|
PARAMETER stop "<|eom_id|>"
|
||||||
|
PARAMETER temperature 1.5
|
||||||
|
PARAMETER min_p 0.1
|
||||||
191
README.md
Normal file
191
README.md
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
---
|
||||||
|
title: Linux Command Generator (Llama 3.2 1B)
|
||||||
|
tags:
|
||||||
|
- text-generation
|
||||||
|
- instruction-tuned
|
||||||
|
- llama
|
||||||
|
- unsloth
|
||||||
|
- lora
|
||||||
|
- linux
|
||||||
|
- command-generation
|
||||||
|
license: other
|
||||||
|
language:
|
||||||
|
- en
|
||||||
|
library_name: transformers
|
||||||
|
pipeline_tag: text-generation
|
||||||
|
datasets:
|
||||||
|
- custom
|
||||||
|
base_model: unsloth/Llama-3.2-1B-Instruct
|
||||||
|
---
|
||||||
|
|
||||||
|
### mecha-org/linux-command-generator-llama3.2-1b
|
||||||
|
|
||||||
|
Natural language → Linux command. A compact Llama 3.2 1B Instruct model fine‑tuned (LoRA) to turn plain‑English requests into correct shell commands.
|
||||||
|
|
||||||
|
## Video Demonstration of the model running on the Mecha Comet
|
||||||
|
<video controls>
|
||||||
|
<source src="https://web-assets.mecha.so/hugging-face/mecha-command-generator-aug-10-2025.mp4" type="video/mp4">
|
||||||
|
Your browser does not support the video tag.
|
||||||
|
</video>
|
||||||
|
For more information of the Mecha Comet, our pocket little handheld computer - click <a href="https://mecha.so/comet">here</a>
|
||||||
|
|
||||||
|
### TL;DR
|
||||||
|
- Base: `unsloth/Llama-3.2-1B-Instruct`
|
||||||
|
- Method: LoRA (r=16, alpha=16, dropout=0)
|
||||||
|
- Context: 2048 tokens
|
||||||
|
- Data: 8,669 pairs across 11 categories
|
||||||
|
- Use cases: quick command lookup, learning CLI, automation
|
||||||
|
|
||||||
|
## Run with Ollama (baby steps)
|
||||||
|
|
||||||
|
1) Install Ollama: see `https://ollama.com/download`.
|
||||||
|
|
||||||
|
2) Verify install:
|
||||||
|
```bash
|
||||||
|
ollama --version
|
||||||
|
```
|
||||||
|
|
||||||
|
3) Run the model interactively:
|
||||||
|
```bash
|
||||||
|
ollama run mecha-org/linux-command-generator-llama3.2-1b
|
||||||
|
```
|
||||||
|
Then type a request, e.g.:
|
||||||
|
- "List all files in the current directory with detailed information"
|
||||||
|
- "Compress the file data.txt using bzip2"
|
||||||
|
- "Find all .py files in the current directory and subdirectories"
|
||||||
|
|
||||||
|
Press Ctrl+C to exit.
|
||||||
|
|
||||||
|
4) One‑off (non‑interactive):
|
||||||
|
```bash
|
||||||
|
ollama run mecha-org/linux-command-generator-llama3.2-1b -p "Display the first 5 lines of access.log"
|
||||||
|
# Expected: head -n 5 access.log
|
||||||
|
```
|
||||||
|
|
||||||
|
5) Get command‑only answers (when needed):
|
||||||
|
```bash
|
||||||
|
ollama run mecha-org/linux-command-generator-llama3.2-1b -p "Output only the command with no explanation. Show system information including kernel version"
|
||||||
|
# Expected: uname -a
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Use a local GGUF with Ollama (fallback)
|
||||||
|
If you have `model.gguf`, put it next to a `Modelfile`:
|
||||||
|
|
||||||
|
```
|
||||||
|
FROM ./model.gguf
|
||||||
|
PARAMETER temperature 0.2
|
||||||
|
PARAMETER top_p 0.9
|
||||||
|
PARAMETER num_ctx 2048
|
||||||
|
SYSTEM You are a Linux command generator. Output only the command with no explanation.
|
||||||
|
TEMPLATE {{ .Prompt }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Create and run:
|
||||||
|
```bash
|
||||||
|
ollama create linux-cmd-gen -f Modelfile
|
||||||
|
ollama run linux-cmd-gen -p "Find all .py files recursively"
|
||||||
|
# Expected: find . -name "*.py"
|
||||||
|
```
|
||||||
|
|
||||||
|
## Other ways to use (optional)
|
||||||
|
|
||||||
|
### Transformers
|
||||||
|
```python
|
||||||
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||||
|
import torch
|
||||||
|
|
||||||
|
model_id = "mecha-org/linux-command-generator-llama3.2-1b"
|
||||||
|
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
||||||
|
model = AutoModelForCausalLM.from_pretrained(model_id, torch_dtype=torch.float16 if torch.cuda.is_available() else None)
|
||||||
|
|
||||||
|
def generate_command(description: str) -> str:
|
||||||
|
messages = [{"role": "user", "content": description}]
|
||||||
|
inputs = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
||||||
|
if torch.cuda.is_available():
|
||||||
|
inputs = inputs.to(model.device)
|
||||||
|
model = model.to("cuda")
|
||||||
|
outputs = model.generate(input_ids=inputs, max_new_tokens=64)
|
||||||
|
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
||||||
|
|
||||||
|
print(generate_command("List all files in the current directory with detailed information"))
|
||||||
|
# -> ls -la
|
||||||
|
```
|
||||||
|
|
||||||
|
### Unsloth
|
||||||
|
```python
|
||||||
|
from unsloth import FastLanguageModel
|
||||||
|
|
||||||
|
model_id = "mecha-org/linux-command-generator-llama3.2-1b"
|
||||||
|
model, tokenizer = FastLanguageModel.from_pretrained(model_name=model_id, max_seq_length=2048)
|
||||||
|
FastLanguageModel.for_inference(model)
|
||||||
|
|
||||||
|
msgs = [{"role": "user", "content": "Compress the file data.txt using bzip2"}]
|
||||||
|
inputs = tokenizer.apply_chat_template(msgs, tokenize=True, add_generation_prompt=True, return_tensors="pt")
|
||||||
|
output = model.generate(input_ids=inputs, max_new_tokens=32)
|
||||||
|
print(tokenizer.decode(output[0], skip_special_tokens=True))
|
||||||
|
# -> bzip2 data.txt
|
||||||
|
```
|
||||||
|
|
||||||
|
## Example prompts → commands
|
||||||
|
- "Show system information including kernel version" → `uname -a`
|
||||||
|
- "Find all .py files in the current directory and subdirectories" → `find . -name "*.py"`
|
||||||
|
- "Display the first 5 lines of access.log" → `head -n 5 access.log`
|
||||||
|
- "Change permissions of script.sh to make it executable for owner" → `chmod +x script.sh`
|
||||||
|
- "Create a tar archive backup.tar containing all files in the documents folder" → `tar -cf backup.tar documents/`
|
||||||
|
|
||||||
|
## Dataset (overview)
|
||||||
|
8,669 input→command pairs across:
|
||||||
|
- Compression & Archiving: bzip2, gzip, tar, zip
|
||||||
|
- File & Directory: cd, cp, find, ls, mkdir, mv, pwd, rm, rmdir, touch
|
||||||
|
- Permissions & Ownership: chgrp, chmod, chown
|
||||||
|
- Viewing & Editing: cat, echo, head, less, tail, vim
|
||||||
|
- Networking: curl, dig, host, ifconfig, ip, netstat, ping, ssh, wget
|
||||||
|
- Package mgmt: apt, dpkg
|
||||||
|
- Process mgmt: kill, killall, nice, pkill, renice
|
||||||
|
- Search & Filter: awk, grep, locate, sed
|
||||||
|
- System info/monitoring: df, du, free, top, uname
|
||||||
|
- User/group: useradd, usermod, groupadd, passwd, sudo
|
||||||
|
- Misc/system control: cron, systemctl, tmux, screen, service
|
||||||
|
|
||||||
|
Format:
|
||||||
|
```json
|
||||||
|
{"input": "Describe what you want to do", "output": "linux_command_here"}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Training details
|
||||||
|
- Base: `unsloth/Llama-3.2-1B-Instruct`
|
||||||
|
- LoRA on attention + MLP projections:
|
||||||
|
- r=16, lora_alpha=16, lora_dropout=0
|
||||||
|
- target_modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
|
||||||
|
- Max sequence length: 2048
|
||||||
|
- SFT on responses only (TRL SFTTrainer), Unsloth-optimized
|
||||||
|
- Example hparams: per‑device batch 2, grad accum 4, epochs 3, lr 2e‑4
|
||||||
|
- Reference: Tesla P100 16GB (~45 minutes), ~2.8GB VRAM (adapters)
|
||||||
|
|
||||||
|
## Safety and responsible use
|
||||||
|
- Always inspect commands before executing.
|
||||||
|
- Avoid destructive operations unless you fully understand consequences.
|
||||||
|
- For apps, add denylists and validations (e.g., block `rm -rf /`, `mkfs`, `dd`).
|
||||||
|
|
||||||
|
## Notes on GGUF
|
||||||
|
- Works with `llama.cpp` and Ollama.
|
||||||
|
- Typical memory (approx.): q4_k_s ~600MB, q4_k_m ~700MB, q8_0 ~1.1GB, f16 ~2.2GB.
|
||||||
|
|
||||||
|
## License
|
||||||
|
Derived from Meta Llama 3.2. Use must comply with the base model license. Check your deployment context for any additional constraints.
|
||||||
|
|
||||||
|
## Citation
|
||||||
|
```
|
||||||
|
@software{hrsvrn_linux_command_generator_llama32_1b,
|
||||||
|
author = {Harshvardhan Vatsa},
|
||||||
|
title = {Linux Command Generator (Llama 3.2 1B)},
|
||||||
|
year = {2025},
|
||||||
|
url = {https://huggingface.co/mecha-org/linux-command-generator-llama3.2-1b}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Acknowledgements
|
||||||
|
- Base: `unsloth/Llama-3.2-1B-Instruct`
|
||||||
|
- Libraries: `unsloth`, `transformers`, `trl`, `accelerate`, `bitsandbytes`
|
||||||
|
|
||||||
3
config.json
Normal file
3
config.json
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"model_type": "llama"
|
||||||
|
}
|
||||||
14
generation_config.json
Normal file
14
generation_config.json
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"bos_token_id": 128000,
|
||||||
|
"do_sample": true,
|
||||||
|
"eos_token_id": [
|
||||||
|
128001,
|
||||||
|
128008,
|
||||||
|
128009
|
||||||
|
],
|
||||||
|
"max_length": 131072,
|
||||||
|
"pad_token_id": 128004,
|
||||||
|
"temperature": 0.6,
|
||||||
|
"top_p": 0.9,
|
||||||
|
"transformers_version": "4.51.3"
|
||||||
|
}
|
||||||
3
model.safetensors
Normal file
3
model.safetensors
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:6f04ff7cf84499647d8378a1119c2315dfe55967b4476b78ab1175344f613e6b
|
||||||
|
size 2471645448
|
||||||
23
special_tokens_map.json
Normal file
23
special_tokens_map.json
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"bos_token": {
|
||||||
|
"content": "<|begin_of_text|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
"eos_token": {
|
||||||
|
"content": "<|eot_id|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
},
|
||||||
|
"pad_token": {
|
||||||
|
"content": "<|finetune_right_pad_id|>",
|
||||||
|
"lstrip": false,
|
||||||
|
"normalized": false,
|
||||||
|
"rstrip": false,
|
||||||
|
"single_word": false
|
||||||
|
}
|
||||||
|
}
|
||||||
BIN
tokenizer.json
(Stored with Git LFS)
Normal file
BIN
tokenizer.json
(Stored with Git LFS)
Normal file
Binary file not shown.
2067
tokenizer_config.json
Normal file
2067
tokenizer_config.json
Normal file
File diff suppressed because it is too large
Load Diff
3
unsloth.F16.gguf
Normal file
3
unsloth.F16.gguf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:ae6c2b1d4f80cdf5e2bb468a556509b0455e8e6c1cd5276b84b5d7c1d24a0edd
|
||||||
|
size 2479595936
|
||||||
3
unsloth.Q4_K_M.gguf
Normal file
3
unsloth.Q4_K_M.gguf
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
version https://git-lfs.github.com/spec/v1
|
||||||
|
oid sha256:322b54702fe7a8e1083c0828f202d748404ea86e52889f0d3b3247cde913b574
|
||||||
|
size 807694752
|
||||||
Reference in New Issue
Block a user