Text Generation
MLX
Safetensors
qwen3_5
user-representation
user-simulation
conversational
8-bit precision
Instructions to use xquantize/userrepgen-4b-8bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use xquantize/userrepgen-4b-8bit with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("xquantize/userrepgen-4b-8bit") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use xquantize/userrepgen-4b-8bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "xquantize/userrepgen-4b-8bit"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "xquantize/userrepgen-4b-8bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use xquantize/userrepgen-4b-8bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "xquantize/userrepgen-4b-8bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "xquantize/userrepgen-4b-8bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8080/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "xquantize/userrepgen-4b-8bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use xquantize/userrepgen-4b-8bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "xquantize/userrepgen-4b-8bit"
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default xquantize/userrepgen-4b-8bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use xquantize/userrepgen-4b-8bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "xquantize/userrepgen-4b-8bit"
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:8080/v1 \ --custom-model-id "xquantize/userrepgen-4b-8bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
File size: 5,643 Bytes
c29119e | 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 | """Generate a task and behavior representation from a conversation."""
import argparse
import json
import sys
import time
from pathlib import Path
import torch
from huggingface_hub import hf_hub_download
from transformers import AutoModelForImageTextToText, AutoTokenizer
# An authored, simplified example inspired by an Excel-help WildChat conversation.
EXAMPLE_CONVERSATION = [
{
"role": "user",
"content": "I need an Excel formula to count dates in A2:A100 before today plus B1.",
},
{
"role": "assistant",
"content": 'Try =COUNTIF(A2:A100,"<"&TODAY()+B1).',
},
{
"role": "user",
"content": "That didn't work. The dates come from another formula.",
},
{
"role": "assistant",
"content": "Are those results actual Excel dates, or text that looks like dates?",
},
{"role": "user", "content": "They're text. Some cells are empty too."},
{
"role": "assistant",
"content": "Convert the nonempty text values with DATEVALUE, then count the resulting dates.",
},
{
"role": "user",
"content": "Can you show the steps using a helper column?",
},
{
"role": "assistant",
"content": 'In C2 enter =IF(A2="","",DATEVALUE(A2)), fill down to C100, then use =COUNTIFS(C2:C100,"<"&TODAY()+B1,C2:C100,">0").',
},
]
def format_prompt(conversation: list[dict[str, str]], template: str) -> str:
if not isinstance(conversation, list) or not conversation:
raise ValueError("The conversation must be a nonempty list of messages.")
for message in conversation:
if not isinstance(message, dict):
raise ValueError("Each message must be an object with role and content.")
if message.get("role") not in ("user", "assistant"):
raise ValueError("Message roles must be 'user' or 'assistant'.")
if not isinstance(message.get("content"), str) or not message["content"].strip():
raise ValueError("Each message must contain nonempty text.")
history = "\n".join(f"[{m['role']}]: {m['content']}" for m in conversation)
return template.format(conversation_history=history)
def parse_representation(text: str) -> dict[str, str]:
representation = json.loads(text)
if not isinstance(representation, dict) or set(representation) != {"task", "user_behavior"}:
raise ValueError(f"Expected exactly task and user_behavior fields; received: {text}")
if not all(isinstance(value, str) and value.strip() for value in representation.values()):
raise ValueError(f"Both representation fields must be nonempty strings; received: {text}")
return representation
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--model", default="microsoft/UserRepGen-4B", help="Hub ID or local model directory.")
parser.add_argument("--conversation", type=Path, help="JSON list of role/content messages; otherwise use the built-in example.")
parser.add_argument("--device", choices=["cpu", "cuda"], default="cuda" if torch.cuda.is_available() else "cpu")
args = parser.parse_args()
conversation = (
json.loads(args.conversation.read_text(encoding="utf-8"))
if args.conversation is not None
else EXAMPLE_CONVERSATION
)
if Path(args.model).is_dir():
prompt_path = Path(args.model) / "representation_prompt.txt"
else:
prompt_path = Path(hf_hub_download(args.model, "representation_prompt.txt"))
prompt = format_prompt(conversation, prompt_path.read_text(encoding="utf-8").strip())
tokenizer = AutoTokenizer.from_pretrained(args.model)
inputs = tokenizer.apply_chat_template(
[{"role": "user", "content": prompt}],
tokenize=True,
add_generation_prompt=True,
enable_thinking=False,
return_tensors="pt",
return_dict=True,
)
prompt_tokens = inputs["input_ids"].shape[1]
if prompt_tokens > 8192:
raise ValueError(f"Prompt has {prompt_tokens} tokens; the supported maximum is 8192.")
if args.device == "cpu":
torch.set_num_threads(8)
print(f"Loading {args.model} on {args.device}; prompt: {prompt_tokens} tokens.", file=sys.stderr, flush=True)
model, loading_info = AutoModelForImageTextToText.from_pretrained(
args.model,
dtype=torch.float32 if args.device == "cpu" else torch.bfloat16,
device_map=args.device,
output_loading_info=True,
)
for key in ("missing_keys", "unexpected_keys", "mismatched_keys", "error_msgs"):
if loading_info.get(key):
raise RuntimeError(f"Checkpoint loading failed ({key}): {loading_info[key]}")
model.eval()
inputs = inputs.to(args.device)
started = time.monotonic()
print("Generating representation...", file=sys.stderr, flush=True)
with torch.inference_mode():
output = model.generate(
**inputs,
max_new_tokens=1024,
do_sample=False,
temperature=None,
top_p=None,
top_k=None,
eos_token_id=tokenizer.eos_token_id,
pad_token_id=tokenizer.pad_token_id,
)
generated_ids = output[0, prompt_tokens:]
text = tokenizer.decode(generated_ids, skip_special_tokens=True).strip()
representation = parse_representation(text)
print(json.dumps(representation, indent=2, ensure_ascii=False))
print(
f"Validated JSON; generated {len(generated_ids)} tokens in {time.monotonic() - started:.1f}s.",
file=sys.stderr,
)
if __name__ == "__main__":
main()
|