Instructions to use BernaLabs/berna-r8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use BernaLabs/berna-r8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="BernaLabs/berna-r8")# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("BernaLabs/berna-r8", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use BernaLabs/berna-r8 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "BernaLabs/berna-r8" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BernaLabs/berna-r8", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/BernaLabs/berna-r8
- SGLang
How to use BernaLabs/berna-r8 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 "BernaLabs/berna-r8" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BernaLabs/berna-r8", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'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 "BernaLabs/berna-r8" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "BernaLabs/berna-r8", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use BernaLabs/berna-r8 with Docker Model Runner:
docker model run hf.co/BernaLabs/berna-r8
Download code/k_vector/k6_percell.py from BernaLabs/berna-r8: direct link, hf CLI and curl.
- Browser
- Download file 1.87 kB
-
https://huggingface.co/BernaLabs/berna-r8/resolve/main/code/k_vector/k6_percell.py
- Command line
-
hf download hf://BernaLabs/berna-r8/code/k_vector/k6_percell.py
-
curl -L -o k6_percell.py https://huggingface.co/BernaLabs/berna-r8/resolve/main/code/k_vector/k6_percell.py
1.87 kB
| """ | |
| K6 — Encompassment per-cell (R8 fix). | |
| R7 bug: K6 = 0.6138 uniform across all cells | |
| Cause: encompassment_engine_v2 uses a global pattern index. | |
| R8 fix: K6[cell] = fraction of layer-distinct fingerprints | |
| that this cell has seen (via fp_history). | |
| """ | |
| import numpy as np | |
| def _hamming_sim(a, b): | |
| """Similarity = 1 - normalized hamming distance on hex strings.""" | |
| if not a or not b or len(a) != len(b): | |
| return 0.0 | |
| try: | |
| x = int(a, 16) ^ int(b, 16) | |
| except ValueError: | |
| return 0.0 | |
| n_bits = len(a) * 4 | |
| dist = bin(x).count("1") / n_bits | |
| return 1.0 - dist | |
| def build_layer_fingerprints(cells, history_window=100): | |
| """Group distinct fingerprints by layer.""" | |
| out = {} | |
| for c in cells: | |
| h = getattr(c, "fp_history", []) | |
| if not h: | |
| continue | |
| out.setdefault(c.layer_idx, set()).update(h[-history_window:]) | |
| return out | |
| def compute_k6_percell(cells, layer_fps, sim_threshold=0.7, | |
| history_window=100): | |
| """ | |
| For each cell: | |
| K6 = fraction of layer's distinct fingerprints | |
| that the cell has 'seen' (similarity >= sim_threshold). | |
| Returns {cell_id: K6 in [0, 1]}. | |
| """ | |
| out = {} | |
| for c in cells: | |
| lfps = layer_fps.get(c.layer_idx, set()) | |
| if not lfps: | |
| out[c.cell_id] = 0.0 | |
| continue | |
| history = getattr(c, "fp_history", []) | |
| if not history: | |
| out[c.cell_id] = 0.0 | |
| continue | |
| recent = history[-history_window:] | |
| matched = 0 | |
| for fp in lfps: | |
| for h in recent: | |
| if _hamming_sim(fp, h) >= sim_threshold: | |
| matched += 1 | |
| break | |
| out[c.cell_id] = matched / max(1, len(lfps)) | |
| return out |