Text Generation
Transformers
Safetensors
GGUF
English
gpt2
chatbot
lora
instruction-tuned
distilled
microllm2
conversational
text-generation-inference
Instructions to use MLVXN/MicroLLM2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MLVXN/MicroLLM2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="MLVXN/MicroLLM2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("MLVXN/MicroLLM2") model = AutoModelForCausalLM.from_pretrained("MLVXN/MicroLLM2", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use MLVXN/MicroLLM2 with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf MLVXN/MicroLLM2:Q4_K_M # Run inference directly in the terminal: llama cli -hf MLVXN/MicroLLM2:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf MLVXN/MicroLLM2:Q4_K_M # Run inference directly in the terminal: llama cli -hf MLVXN/MicroLLM2:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf MLVXN/MicroLLM2:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf MLVXN/MicroLLM2:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf MLVXN/MicroLLM2:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf MLVXN/MicroLLM2:Q4_K_M
Use Docker
docker model run hf.co/MLVXN/MicroLLM2:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use MLVXN/MicroLLM2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "MLVXN/MicroLLM2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "MLVXN/MicroLLM2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/MLVXN/MicroLLM2:Q4_K_M
- SGLang
How to use MLVXN/MicroLLM2 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 "MLVXN/MicroLLM2" \ --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": "MLVXN/MicroLLM2", "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 "MLVXN/MicroLLM2" \ --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": "MLVXN/MicroLLM2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use MLVXN/MicroLLM2 with Ollama:
ollama run hf.co/MLVXN/MicroLLM2:Q4_K_M
- Unsloth Studio
How to use MLVXN/MicroLLM2 with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for MLVXN/MicroLLM2 to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for MLVXN/MicroLLM2 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for MLVXN/MicroLLM2 to start chatting
- Docker Model Runner
How to use MLVXN/MicroLLM2 with Docker Model Runner:
docker model run hf.co/MLVXN/MicroLLM2:Q4_K_M
- Lemonade
How to use MLVXN/MicroLLM2 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull MLVXN/MicroLLM2:Q4_K_M
Run and chat with the model
lemonade run user.MicroLLM2-Q4_K_M
List all available models
lemonade list
- Atomic Chat
File size: 4,068 Bytes
5797bb9 | 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 | #!/usr/bin/env python3
"""
MicroLLM2 Interactive Chat Loop
- Loads MLVXN/MicroLLM2 (or local ./microllm2-checkpoints/final_merged)
- ChatML: <|im_start|>user / assistant
- Works on H100 (bf16) and local CPU
- Run: python chat_loop.py [--local] [--temp 0.7]
No token hardcoded — uses HF_TOKEN env if private, else public pull.
"""
import os, sys, torch
from pathlib import Path
# Use local checkpoint if available (faster on H100), else HF
LOCAL = Path("/home/zeus/microllm2/microllm2-checkpoints/final_merged")
HF_ID = "MLVXN/MicroLLM2"
MODEL_ID = str(LOCAL) if LOCAL.exists() else HF_ID
# Allow override
if "--local" in sys.argv and LOCAL.exists():
MODEL_ID = str(LOCAL)
elif "--hf" in sys.argv:
MODEL_ID = HF_ID
print(f"[*] Loading MicroLLM2 from {MODEL_ID} ...")
try:
from transformers import AutoTokenizer, AutoModelForCausalLM
except ImportError:
print("pip install transformers accelerate torch"); sys.exit(1)
tok = AutoTokenizer.from_pretrained(MODEL_ID, trust_remote_code=False)
if tok.pad_token is None:
tok.pad_token = tok.eos_token
# Ensure ChatML tokens exist
if "<|im_start|>" not in tok.get_vocab():
tok.add_special_tokens({"additional_special_tokens": ["<|im_start|>", "<|im_end|>"]})
dtype = torch.bfloat16 if torch.cuda.is_available() else torch.float32
device_map = "auto" if torch.cuda.is_available() else None
try:
model = AutoModelForCausalLM.from_pretrained(
MODEL_ID, torch_dtype=dtype, device_map=device_map,
trust_remote_code=False, attn_implementation="sdpa"
)
except Exception as e:
print(f"[!] sdpa load failed {e}, retry without attn arg")
model = AutoModelForCausalLM.from_pretrained(MODEL_ID, torch_dtype=dtype, device_map=device_map)
model.eval()
device = next(model.parameters()).device
print(f"[+] Loaded on {device} ({dtype}) — {model.num_parameters()/1e9:.2f}B params")
print(f"[+] MicroLLM2 by Maximalist Labs — type 'exit' to quit, 'clear' to reset history\n")
# Chat history as list of dicts for ChatML
history = []
def format_prompt(history, user_msg):
# Build ChatML prompt
msgs = history + [{"role": "user", "content": user_msg}]
parts = []
for m in msgs:
parts.append(f"<|im_start|>{m['role']}\n{m['content']}<|im_end|>")
parts.append("<|im_start|>assistant\n")
return "\n".join(parts)
# Generation defaults — tuned for GPT2-XL 1.5B chat
temp = 0.7
top_p = 0.9
max_new = 120
if "--temp" in sys.argv:
try: temp = float(sys.argv[sys.argv.index("--temp")+1])
except: pass
while True:
try:
user = input("\nYou: ").strip()
except (EOFError, KeyboardInterrupt):
print("\nbye"); break
if not user:
continue
if user.lower() in ("exit","quit","q"):
break
if user.lower() in ("clear","reset","new"):
history = []; print("[*] history cleared"); continue
prompt = format_prompt(history, user)
inputs = tok(prompt, return_tensors="pt", truncation=True, max_length=900).to(device)
# Warn if truncated (1024 limit)
if inputs.input_ids.shape[1] >= 900:
print("[!] near 1024 ctx — consider 'clear'")
with torch.no_grad():
out = model.generate(
**inputs, max_new_tokens=max_new, do_sample=(temp>0),
temperature=temp if temp>0 else 1.0, top_p=top_p,
repetition_penalty=1.1, pad_token_id=tok.eos_token_id,
eos_token_id=tok.convert_tokens_to_ids("<|im_end|>") if "<|im_end|>" in tok.get_vocab() else tok.eos_token_id,
)
# Decode only new tokens
gen = out[0][inputs.input_ids.shape[1]:]
text = tok.decode(gen, skip_special_tokens=False)
# Strip ChatML tail
if "<|im_end|>" in text:
text = text.split("<|im_end|>")[0]
text = text.replace("<|endoftext|>", "").strip()
print(f"\nMicroLLM2: {text}")
# Keep history (trim to last 6 turns to stay <1024)
history.append({"role": "user", "content": user})
history.append({"role": "assistant", "content": text})
if len(history) > 12:
history = history[-12:]
print("done")
|