Text Generation
Transformers
Safetensors
olmo_hybrid
risc-v
compiled-weights
olmo-hybrid
gated-deltanet
tool-use
Instructions to use jgalego/olmputer-tiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use jgalego/olmputer-tiny with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="jgalego/olmputer-tiny")# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("jgalego/olmputer-tiny") model = AutoModelForCausalLM.from_pretrained("jgalego/olmputer-tiny", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use jgalego/olmputer-tiny with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "jgalego/olmputer-tiny" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "jgalego/olmputer-tiny", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/jgalego/olmputer-tiny
- SGLang
How to use jgalego/olmputer-tiny 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 "jgalego/olmputer-tiny" \ --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": "jgalego/olmputer-tiny", "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 "jgalego/olmputer-tiny" \ --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": "jgalego/olmputer-tiny", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use jgalego/olmputer-tiny with Docker Model Runner:
docker model run hf.co/jgalego/olmputer-tiny
Upload folder using huggingface_hub
Browse files- README.md +34 -10
- example.py +34 -0
README.md
CHANGED
|
@@ -63,23 +63,47 @@ A run, from an ELF to the HALT token:
|
|
| 63 |
|
| 64 |
## Usage
|
| 65 |
|
|
|
|
|
|
|
| 66 |
```bash
|
| 67 |
-
|
| 68 |
```
|
| 69 |
|
| 70 |
```python
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
|
|
|
|
| 74 |
from chipformer.q35.ir import OLMO
|
| 75 |
-
from chipformer.rv import core, firmware, ref
|
| 76 |
from chipformer.rv.programs import program
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
```
|
| 84 |
|
| 85 |
-
`firmware.run` loads the program's ROM, RAM and registers into the linear-attention layers' recurrent states after a one-token prefix, starts the CPU with GO and decodes greedily until HALT.
|
|
|
|
| 63 |
|
| 64 |
## Usage
|
| 65 |
|
| 66 |
+
[`example.py`](example.py) runs fibonacci(25) on olmo-tiny: greedy `generate` runs the CPU, and the result is read from the trace the model wrote. It is a [uv script](https://docs.astral.sh/uv/guides/scripts/) that declares its own dependencies:
|
| 67 |
+
|
| 68 |
```bash
|
| 69 |
+
uv run https://huggingface.co/jgalego/olmputer-tiny/resolve/main/example.py
|
| 70 |
```
|
| 71 |
|
| 72 |
```python
|
| 73 |
+
# /// script
|
| 74 |
+
# requires-python = ">=3.12"
|
| 75 |
+
# dependencies = [
|
| 76 |
+
# "chipformer @ https://github.com/JGalego/olmputer/archive/98639dff4c84a18542e3ca12a286a4df563b3a27.tar.gz#subdirectory=experimental/riscv", # pylint: disable=line-too-long
|
| 77 |
+
# "huggingface_hub",
|
| 78 |
+
# "torch==2.14.1",
|
| 79 |
+
# "transformers==5.19.0",
|
| 80 |
+
# ]
|
| 81 |
+
# ///
|
| 82 |
+
"""Run a RISC-V program on olmo-tiny: fibonacci(25), computed by the computer in its weights.
|
| 83 |
+
|
| 84 |
+
The program's code and registers are written into the model's Gated DeltaNet states; greedy
|
| 85 |
+
generate then runs the CPU, every generated token being the next token of its execution trace.
|
| 86 |
+
The program ends with mv a0, t0 (fibonacci(25)), li a7, 93 and the exit ecall, so the result is
|
| 87 |
+
the value of the second-to-last value record the model wrote.
|
| 88 |
+
"""
|
| 89 |
|
| 90 |
+
import torch
|
| 91 |
from chipformer.q35.ir import OLMO
|
| 92 |
+
from chipformer.rv import core, firmware, ref, spec
|
| 93 |
from chipformer.rv.programs import program
|
| 94 |
+
from transformers import OlmoHybridForCausalLM
|
| 95 |
|
| 96 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 97 |
+
MODEL = OlmoHybridForCausalLM.from_pretrained("jgalego/olmputer-tiny", dtype=torch.bfloat16)
|
| 98 |
+
MODEL = MODEL.to(DEVICE).eval()
|
| 99 |
+
CIRCUIT = core.build(OLMO) # the CPU as a circuit: it writes the program into the model's cache
|
| 100 |
+
|
| 101 |
+
TRACE = firmware.run(MODEL, CIRCUIT, ref.Machine.from_program(program("fib")))
|
| 102 |
+
VALUES = [spec.decode_value(TRACE[:i + 1]) for i, t in enumerate(TRACE)
|
| 103 |
+
if spec.family(t)[0] in ("F0", "F1", "F2")]
|
| 104 |
+
print("fibonacci(25) =", VALUES[-2])
|
| 105 |
+
print(f"{len(TRACE)} trace tokens on {DEVICE}, identical to the reference machine:",
|
| 106 |
+
TRACE == ref.Machine.from_program(program("fib")).run()[1:])
|
| 107 |
```
|
| 108 |
|
| 109 |
+
A GPU takes under a minute; a CPU works too, more slowly. `firmware.run` loads the program's ROM, RAM and registers into the linear-attention layers' recurrent states after a one-token prefix, starts the CPU with GO and decodes greedily until HALT.
|
example.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# /// script
|
| 2 |
+
# requires-python = ">=3.12"
|
| 3 |
+
# dependencies = [
|
| 4 |
+
# "chipformer @ https://github.com/JGalego/olmputer/archive/98639dff4c84a18542e3ca12a286a4df563b3a27.tar.gz#subdirectory=experimental/riscv", # pylint: disable=line-too-long
|
| 5 |
+
# "huggingface_hub",
|
| 6 |
+
# "torch==2.14.1",
|
| 7 |
+
# "transformers==5.19.0",
|
| 8 |
+
# ]
|
| 9 |
+
# ///
|
| 10 |
+
"""Run a RISC-V program on olmo-tiny: fibonacci(25), computed by the computer in its weights.
|
| 11 |
+
|
| 12 |
+
The program's code and registers are written into the model's Gated DeltaNet states; greedy
|
| 13 |
+
generate then runs the CPU, every generated token being the next token of its execution trace.
|
| 14 |
+
The program ends with mv a0, t0 (fibonacci(25)), li a7, 93 and the exit ecall, so the result is
|
| 15 |
+
the value of the second-to-last value record the model wrote.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
import torch
|
| 19 |
+
from chipformer.q35.ir import OLMO
|
| 20 |
+
from chipformer.rv import core, firmware, ref, spec
|
| 21 |
+
from chipformer.rv.programs import program
|
| 22 |
+
from transformers import OlmoHybridForCausalLM
|
| 23 |
+
|
| 24 |
+
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
| 25 |
+
MODEL = OlmoHybridForCausalLM.from_pretrained("jgalego/olmputer-tiny", dtype=torch.bfloat16)
|
| 26 |
+
MODEL = MODEL.to(DEVICE).eval()
|
| 27 |
+
CIRCUIT = core.build(OLMO) # the CPU as a circuit: it writes the program into the model's cache
|
| 28 |
+
|
| 29 |
+
TRACE = firmware.run(MODEL, CIRCUIT, ref.Machine.from_program(program("fib")))
|
| 30 |
+
VALUES = [spec.decode_value(TRACE[:i + 1]) for i, t in enumerate(TRACE)
|
| 31 |
+
if spec.family(t)[0] in ("F0", "F1", "F2")]
|
| 32 |
+
print("fibonacci(25) =", VALUES[-2])
|
| 33 |
+
print(f"{len(TRACE)} trace tokens on {DEVICE}, identical to the reference machine:",
|
| 34 |
+
TRACE == ref.Machine.from_program(program("fib")).run()[1:])
|