Instructions to use Ninnix96/Qwengram-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use Ninnix96/Qwengram-4B 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 Ninnix96/Qwengram-4B:Q4_K_M # Run inference directly in the terminal: llama cli -hf Ninnix96/Qwengram-4B:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf Ninnix96/Qwengram-4B:Q4_K_M # Run inference directly in the terminal: llama cli -hf Ninnix96/Qwengram-4B:Q4_K_M
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf Ninnix96/Qwengram-4B:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama cli -hf Ninnix96/Qwengram-4B:Q4_K_M
Use Docker
docker model run hf.co/Ninnix96/Qwengram-4B:Q4_K_M
- Llama new
- LM Studio
- Jan
- vLLM
How to use Ninnix96/Qwengram-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Ninnix96/Qwengram-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Ninnix96/Qwengram-4B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Ninnix96/Qwengram-4B:Q4_K_M
- Ollama
How to use Ninnix96/Qwengram-4B with Ollama:
ollama run hf.co/Ninnix96/Qwengram-4B:Q4_K_M
- Unsloth Desktop
- Pi
How to use Ninnix96/Qwengram-4B with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf Ninnix96/Qwengram-4B:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:9931/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "Ninnix96/Qwengram-4B:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use Ninnix96/Qwengram-4B with Docker Model Runner:
docker model run hf.co/Ninnix96/Qwengram-4B:Q4_K_M
- Lemonade
How to use Ninnix96/Qwengram-4B with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull Ninnix96/Qwengram-4B:Q4_K_M
Run and chat with the model
lemonade run user.Qwengram-4B-Q4_K_M
List all available models
lemonade list
- Hermes Agent
How to use Ninnix96/Qwengram-4B with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf Ninnix96/Qwengram-4B:Q4_K_M
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:9931/v1 hermes config set model.default Ninnix96/Qwengram-4B:Q4_K_M
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use Ninnix96/Qwengram-4B with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf Ninnix96/Qwengram-4B:Q4_K_M
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:9931/v1 \ --custom-model-id "Ninnix96/Qwengram-4B:Q4_K_M" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Download runtime/package.py from Ninnix96/Qwengram-4B: direct link, hf CLI and curl.
- Browser
- Download file 6.76 kB
-
https://huggingface.co/Ninnix96/Qwengram-4B/resolve/main/runtime/package.py
- Command line
-
hf download hf://Ninnix96/Qwengram-4B/runtime/package.py
-
curl -L -o package.py https://huggingface.co/Ninnix96/Qwengram-4B/resolve/main/runtime/package.py
6.76 kB
| import hashlib | |
| import json | |
| import os | |
| import shutil | |
| import sys | |
| from pathlib import Path | |
| import numpy as np | |
| import torch | |
| from safetensors.torch import load_file | |
| HERE = Path(__file__).resolve().parent | |
| TRACK = HERE.parent | |
| ROOT = TRACK.parent | |
| sys.path.insert(0, str(ROOT / 'llama.cpp/gguf-py')) | |
| import gguf | |
| ART = TRACK / '.artifacts/gguf' | |
| OUT = ART / 'release' | |
| SOURCE = TRACK / '.artifacts/checkpoints' | |
| def sha(path): | |
| with path.open('rb') as f: | |
| return hashlib.file_digest(f, 'sha256').hexdigest() | |
| def main(): | |
| OUT.mkdir(parents=True, exist_ok=True) | |
| definition = json.loads((TRACK / 'qwengram-4b.json').read_text()) | |
| assert 'pending' not in definition['status'].lower() | |
| assert definition['recipe'] == 'REAL-15M + linear750' | |
| assert definition['reader_tokens'] == 15000064 | |
| reader_path = SOURCE / definition['reader_file'] | |
| gate_path = TRACK / '.artifacts' / definition['arbiter_file'] | |
| if not gate_path.exists(): | |
| gate_path = SOURCE / definition['arbiter_file'] | |
| assert sha(reader_path) == definition['reader_sha256'] | |
| assert sha(gate_path) == definition['arbiter_sha256'] | |
| reader = load_file(reader_path) | |
| gate = torch.load(gate_path, map_location='cpu', weights_only=False) | |
| assert gate['tokens'] == 749568 | |
| assert gate['reader_sha256'] == definition['reader_sha256'] | |
| assert gate['injection_idx'] == [3, 11] | |
| assert gate['target_revision'] == definition['backbone_revision'] | |
| assert gate['tokenizer_sha256'] == definition['tokenizer_sha256'] | |
| keys = {'readers.%d.%s' % (layer, name) for layer in (3, 11) | |
| for name in ('keys.0.weight', 'value.weight', 'beta', 'gamma')} | |
| assert set(reader) == keys | |
| for layer in (3, 11): | |
| for name in ('keys.0.weight', 'value.weight'): | |
| assert reader['readers.%d.%s' % (layer, name)].shape == (2560, 2560) | |
| assert gate['w'].shape == (2560,) | |
| alpha = 0.75 + torch.sigmoid(gate['alpha2_raw']) | |
| assert abs(alpha.item() - definition['early_alpha']) < 1e-7 | |
| tensors = {'qwengram.' + k: v.contiguous() for k, v in reader.items()} | |
| tensors.update({'qwengram.arbiter.w': gate['w'].contiguous(), | |
| 'qwengram.arbiter.b': gate['b'].contiguous(), | |
| 'qwengram.arbiter.alpha2': alpha}) | |
| assert len(tensors) == 11 | |
| assert all(v.dtype == torch.float32 and torch.isfinite(v).all() for v in tensors.values()) | |
| base = gguf.GGUFReader(ART / 'stock-BF16.gguf') | |
| assert base.get_field('general.architecture').contents() == 'qwen35' | |
| assert base.get_field('qwen35.embedding_length').contents() == 2560 | |
| assert base.get_field('qwen35.block_count').contents() - base.get_field('qwen35.nextn_predict_layers').contents() == 32 | |
| path = OUT / 'QwenGram-4B-BF16.gguf' | |
| temp = path.with_suffix('.gguf.tmp') | |
| writer = gguf.GGUFWriter(temp, 'qwen35') | |
| for name, field in base.fields.items(): | |
| if name.startswith('GGUF.') or name == 'general.architecture': | |
| continue | |
| value = field.contents() | |
| if name == 'general.name': | |
| value = 'QwenGram-4B ' + definition['recipe'] | |
| writer.add_key_value(name, value, field.types[0], | |
| field.types[-1] if field.types[0] == gguf.GGUFValueType.ARRAY else None) | |
| strings = {'version': '1', 'base_revision': definition['backbone_revision'], | |
| 'ple_revision': definition['ple_revision'], | |
| 'reader_sha256': definition['reader_sha256'], | |
| 'arbiter_sha256': definition['arbiter_sha256'], | |
| 'tokenizer_sha256': definition['tokenizer_sha256'], | |
| 'recipe': definition['recipe'], 'reader_layers': 'IDX3,IDX11 (zero-based)', | |
| 'alpha_late': '0.5*sigmoid(dot(w,RMSNorm(h11))+b)', | |
| 'ple_source': definition['ple_model'], | |
| 'ple_addressing': 'splitmix64 n-gram hash, head-preserving prime tables', | |
| 'reader_math': 'h + alpha*gamma*sigmoid(dot(RMSNorm(h),RMSNorm(key(m)))/sqrt(2560)+beta)*value(m)'} | |
| for name, value in strings.items(): | |
| writer.add_string('qwengram.' + name, value) | |
| integers = {'reader_early_layer': 3, 'reader_late_layer': 11, 'reader_branches': 1, 'reader_memory_dim': 2560, 'reader_hidden_dim': 2560, | |
| 'ple_seed': 1234, 'ple_ngram': 3, 'ple_heads_per_ngram': 8, | |
| 'ple_vocab_base': 20000000, 'ple_vocab_size': 248320, 'ple_eos': 248044, | |
| 'ple_row_dim': 160, 'ple_slots': 16, | |
| 'reader_tokens': definition['reader_tokens'], 'calibration_tokens': 749568} | |
| for name, value in integers.items(): | |
| writer.add_uint32('qwengram.' + name, value) | |
| writer.add_float32('qwengram.alpha2', alpha.item()) | |
| writer.add_float32('qwengram.ple_weight_scale', 0.00019931793212890625) | |
| writer.add_bool('qwengram.external_ple_required', True) | |
| for tensor in base.tensors: | |
| writer.add_tensor(tensor.name, tensor.data, raw_dtype=tensor.tensor_type) | |
| for name, value in tensors.items(): | |
| writer.add_tensor(name, value.numpy().reshape(-1) if value.ndim == 0 else value.numpy()) | |
| writer.write_header_to_file() | |
| writer.write_kv_data_to_file() | |
| writer.write_tensors_to_file() | |
| writer.close() | |
| with temp.open('rb') as f: | |
| os.fsync(f.fileno()) | |
| check = gguf.GGUFReader(temp) | |
| by_name = {t.name: t for t in check.tensors} | |
| assert len(by_name) == len(base.tensors) + 11 | |
| for tensor in base.tensors: | |
| other = by_name[tensor.name] | |
| assert other.tensor_type == tensor.tensor_type | |
| assert np.array_equal(other.shape, tensor.shape) | |
| assert np.array_equal(other.data, tensor.data), tensor.name | |
| for name, value in tensors.items(): | |
| other = by_name[name] | |
| assert other.tensor_type == gguf.GGMLQuantizationType.F32 | |
| assert np.array_equal(other.data, value.numpy().reshape(other.data.shape)), name | |
| os.replace(temp, path) | |
| for name in ('LICENSE', 'chat_template.jinja', 'tokenizer.json', 'tokenizer_config.json'): | |
| shutil.copyfile(ART / 'base' / name, OUT / name) | |
| shutil.copyfile(TRACK / 'qwengram-4b.json', OUT / 'qwengram-4b.json') | |
| shutil.copyfile(reader_path, OUT / 'reader.safetensors') | |
| shutil.copyfile(gate_path, OUT / 'arbiter.pt') | |
| result = {'file': path.name, 'sha256': sha(path), 'bytes': path.stat().st_size, | |
| 'reader_sha256': definition['reader_sha256'], 'arbiter_sha256': definition['arbiter_sha256'], | |
| 'stock_backbone_sha256': sha(ART / 'stock-BF16.gguf'), | |
| 'exact_backbone_tensors': len(base.tensors), 'exact_fp32_extension_tensors': 11} | |
| (HERE / 'packaging.json').write_text(json.dumps(result, indent=2) + '\n') | |
| print(json.dumps(result, indent=2)) | |
| if __name__ == '__main__': | |
| main() | |