Text Generation
Transformers
Safetensors
qwen3_5_text
merlin-agent
quantum-classical
quantum-kernel
ibm-quantum
otoc
quantum-provenance
merlin-research
code
conversational
Instructions to use Merlin-Research/Merlin-Agent with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Merlin-Research/Merlin-Agent with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Merlin-Research/Merlin-Agent") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("Merlin-Research/Merlin-Agent") model = AutoModelForCausalLM.from_pretrained("Merlin-Research/Merlin-Agent") 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
- vLLM
How to use Merlin-Research/Merlin-Agent with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Merlin-Research/Merlin-Agent" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Merlin-Research/Merlin-Agent", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Merlin-Research/Merlin-Agent
- SGLang
How to use Merlin-Research/Merlin-Agent 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 "Merlin-Research/Merlin-Agent" \ --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": "Merlin-Research/Merlin-Agent", "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 "Merlin-Research/Merlin-Agent" \ --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": "Merlin-Research/Merlin-Agent", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Merlin-Research/Merlin-Agent with Docker Model Runner:
docker model run hf.co/Merlin-Research/Merlin-Agent
File size: 2,402 Bytes
1502abe f70f582 1502abe | 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 | """Merlin-Agent modeling: Qwen3_5 text causal LM with per-layer quantum injection.
At each full-attention layer, a fixed quantum-derived direction (buffer q_k) is
added to that layer's output hidden state with an RMS-matched, alpha-scaled
magnitude. Injection lives in the model (buffers + hooks re-installed in
__init__), so it survives save/reload — not a bare, non-persisted hook.
alpha == 0 -> exact base model.
"""
import torch
try:
from transformers import Qwen3_5ForCausalLM
except ImportError: # not exported at top level in some transformers versions
from transformers.models.qwen3_5.modeling_qwen3_5 import Qwen3_5ForCausalLM
try:
from .configuration_merlin_agent import MerlinAgentConfig
except ImportError: # when loaded as flat remote code (trust_remote_code)
from configuration_merlin_agent import MerlinAgentConfig
def _inject(h: torch.Tensor, q: torch.Tensor, alpha: float) -> torch.Tensor:
if alpha == 0:
return h
q = q.to(dtype=h.dtype, device=h.device)
rms_h = h.pow(2).mean(dim=-1, keepdim=True).sqrt()
rms_q = q.pow(2).mean().sqrt().clamp_min(1e-6)
return h + alpha * (rms_h / rms_q) * q
class MerlinAgentForCausalLM(Qwen3_5ForCausalLM):
config_class = MerlinAgentConfig
def __init__(self, config):
super().__init__(config)
self._inj_layers = list(config.full_attention_layer_indices)
for k in range(len(self._inj_layers)):
self.register_buffer(f"q_{k}", torch.zeros(config.hidden_size), persistent=True)
self._install_injection_hooks()
def _install_injection_hooks(self):
for k, li in enumerate(self._inj_layers):
self.model.layers[li].register_forward_hook(self._make_hook(f"q_{k}"))
def _make_hook(self, qk: str):
def hook(module, args, output):
q = getattr(self, qk)
a = float(self.config.quantum_injection_alpha)
if isinstance(output, tuple):
return (_inject(output[0], q, a),) + tuple(output[1:])
return _inject(output, q, a)
return hook
def set_quantum_signatures(self, q_vectors):
"""Load the 8 projected quantum direction vectors (each shape [hidden_size])."""
assert len(q_vectors) == len(self._inj_layers)
for k, v in enumerate(q_vectors):
getattr(self, f"q_{k}").copy_(torch.as_tensor(v, dtype=torch.float32))
|