A fine-tuned version of LiquidAI/LFM2.5-350M specialized for converting natural language instructions into Linux shell commands.
What This Model Actually Is
This is a task-specific fine-tune of LiquidAI's 350M parameter language model, trained to generate bash commands wrapped in special tokens. It was created as a research/demonstration project to explore:
LoRA fine-tuning for command generation tasks
GRPO (Group Relative Policy Optimization) for reinforcement learning from rewards
Custom format training using special tokens
Production pipeline with Azure OpenAI dataset generation
Architecture & Training
Base Model
Model: LiquidAI/LFM2.5-350M (350M parameters)
Architecture: Transformer decoder-only
Context Length: 4096 tokens
Training Pipeline
OpenAI GPT-4 Dataset (3,000 examples)
↓
SFT Training (4 epochs, LoRA r=16, BF16)
- assistant_only_loss=True
- Custom data collator with assistant_masks
↓
GRPO Training (2 epochs, 7 reward functions)
- beta=0.04 (KL constraint)
- num_generations=3 per prompt
- Temperature annealing 0.7 → 0.45
↓
Final Merged Model
Dataset (15 Categories, ~3,000 examples)
Category
Examples
Description
file_operations
450
ls, cp, mv, rm, mkdir
text_processing
400
grep, awk, sed, cut, sort
file_search
300
find, locate, which
process_management
300
ps, kill, pkill, nohup
networking
250
ping, curl, wget, ssh, scp
permissions
200
chmod, chown, sudo
archives_compression
200
tar, gzip, zip
system_info
200
df, du, free, uptime
io_redirection
200
pipes, >, >>, tee
environment
150
export, alias, source
monitoring
150
watch, lsof, journalctl
user_management
150
useradd, passwd, id
disk_storage
150
lsblk, mount, fdisk
string_patterns
150
grep -E, sed -E patterns
shell_scripting
150
for loops, if statements
Output Format (v30)
The model outputs raw bash commands between special tokens:
reward_format: Correct special token usage (+2/-1)
reward_tool_name: Raw command format validation (+2/-2)
reward_exact_cmd: Exact string match (+2, partial credit)
reward_similarity: Token F1 similarity (0-1)
reward_safety: Dangerous command penalty (-3)
reward_penalties: Termination and structure quality
reward_structure: Content quality and format
3. Critical Bug Fixes Applied
Tokenizer Patch for GRPO
python
1# TRL's GRPOTrainer calls batch_decode with skip_special_tokens=True2# which strips our format tokens. We monkey-patch to force=False.3def_forced_decode(sequences, skip_special_tokens=True,**kwargs):4return original(sequences, skip_special_tokens=False,**kwargs)
Pickle Fix for odict_keys
python
1# TRL/Transformers has issues with odict_keys in save checkpoints2# We monkey-patch Trainer._save to convert to list before saving3defpatched_save(self, output_dir, state_dict):4ifhasattr(self,'model_kwarg_keys'):5ifisinstance(keys,(KeysView, ValuesView, ItemsView)):6 self.model_kwarg_keys =list(keys)7# ... sanitize and save
4. Training Optimizations
Right padding for training (assistant_only_loss requirement)
BF16 mixed precision for speed
Gradient checkpointing for memory
Temperature annealing (0.7 → 0.45) for exploration → exploitation
Milestone checkpoints at 10%, 50%, 100%
Usage
Basic Inference
python
1from transformers import AutoModelForCausalLM, AutoTokenizer
2import torch
3import re
45model_id ="2796gauravc/lfm25-350m-linux-grpo"6tokenizer = AutoTokenizer.from_pretrained(model_id)7model = AutoModelForCausalLM.from_pretrained(8 model_id,9 torch_dtype=torch.bfloat16,10 device_map="auto"11)1213# Prepare prompt14messages =[15{"role":"system","content":"You are a Linux command assistant."},16{"role":"user","content":"Find all PDF files modified in the last 7 days"}17]1819# Tokenize20enc = tokenizer.apply_chat_template(21 messages,22 add_generation_prompt=True,23 return_tensors="pt"24)25input_ids = enc.input_ids.to(model.device)26attention_mask = enc.attention_mask.to(model.device)2728# Generate29with torch.no_grad():30 outputs = model.generate(31 input_ids=input_ids,32 attention_mask=attention_mask,33 max_new_tokens=100,34 do_sample=False,35 pad_token_id=tokenizer.pad_token_id
36)3738# Decode with special tokens preserved39response = tokenizer.decode(40 outputs[0][input_ids.size(-1):],41 skip_special_tokens=False42)4344# Extract command45match= re.search(46r"<\|tool_call_start\|>(.*?)<\|tool_call_end\|>",47 response,48 re.DOTALL
49)50ifmatch:51 command =match.group(1).strip()52print(f"Generated: {command}")53# Output: find . -name "*.py" -mtime -7
Hardware Requirements
Mode
VRAM
RAM
Speed
Inference (GPU)
2GB
4GB
~100 tokens/s
Inference (CPU)
-
4GB
~20 tokens/s
Training (SFT)
16GB
32GB
~2 hrs
Training (GRPO)
20GB
32GB
~3 hrs
Limitations & Honest Assessment
What It Does Well
✅ Format compliance: Always uses correct special tokens
✅ Simple commands: Good at basic file operations, text processing
✅ Edge deployment: Small enough to run on consumer hardware
✅ No function wrappers: Clean raw command output
What It Struggles With
❌ Complex pipelines: Multi-stage commands with pipes
❌ Exact match: Only 24% match reference exactly (but many alternatives are valid)
❌ Edge cases: Unusual flags or rare utilities
❌ Context awareness: No memory of previous commands
Known Issues
Semantic equivalence not string equivalence: Many valid bash commands exist for the same task. The model may generate a correct alternative that doesn't match the reference string.
Safety: While we filter dangerous patterns in training, the model could still suggest risky commands. Always review before execution.
Overfitting to training patterns: May repeat common patterns from the training data.
Citation
bibtex
1@misc{lfm25-350m-linux-grpo,
2 title={LFM2.5-350M Linux Command Generator},
3 author={Gaurav Chauhan},
4 year={2026},
5 howpublished={\url{https://huggingface.co/2796gauravc/lfm25-350m-linux-grpo}},
6 note={350M parameter NL2Bash model with LoRA + GRPO training}
7}