Text-to-Image
Diffusers
Safetensors
GGUF
English
TeverationPipeline
teveration
image-to-image
depth-estimation
image-segmentation
ternary
quantized
jeveration
qwen3.5
bonsai
comfyui
custom_code
conversational
Run this model with HF Jobs
Run DmitrofNET/Teveration-1 on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/DmitrofNET/Teveration-1. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/DmitrofNET/Teveration-1 on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use DmitrofNET/Teveration-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use DmitrofNET/Teveration-1 with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("DmitrofNET/Teveration-1", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use DmitrofNET/Teveration-1 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 DmitrofNET/Teveration-1 # Run inference directly in the terminal: llama cli -hf DmitrofNET/Teveration-1
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf DmitrofNET/Teveration-1 # Run inference directly in the terminal: llama cli -hf DmitrofNET/Teveration-1
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 DmitrofNET/Teveration-1 # Run inference directly in the terminal: ./build/bin/llama cli -hf DmitrofNET/Teveration-1
Use Docker
docker model run hf.co/DmitrofNET/Teveration-1
- Llama new
- LM Studio
- Jan
- Draw Things
- DiffusionBee
- Ollama
How to use DmitrofNET/Teveration-1 with Ollama:
ollama run hf.co/DmitrofNET/Teveration-1
- Unsloth Desktop
- Pi
How to use DmitrofNET/Teveration-1 with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf DmitrofNET/Teveration-1
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": "DmitrofNET/Teveration-1" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use DmitrofNET/Teveration-1 with Docker Model Runner:
docker model run hf.co/DmitrofNET/Teveration-1
- Lemonade
How to use DmitrofNET/Teveration-1 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull DmitrofNET/Teveration-1
Run and chat with the model
lemonade run user.Teveration-1-{{QUANT_TAG}}List all available models
lemonade list
- Hermes Agent
How to use DmitrofNET/Teveration-1 with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf DmitrofNET/Teveration-1
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 DmitrofNET/Teveration-1
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use DmitrofNET/Teveration-1 with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf DmitrofNET/Teveration-1
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 "DmitrofNET/Teveration-1" \ --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"
One file per model: small, balanced, high; loader and model card updated
Browse filesFiles changed (9)
- README.md+19-17
- Teveration-1-adapter-Q4_0.ggufDeleted-3
- Teveration-1-adapter-Q6_mix.ggufDeleted-3
- Teveration-1-adapter-Q8_0.ggufDeleted-3
- Teveration-1-backbone-PTQ1_0.ggufDeleted-3
- Teveration-1-image-Q4_0.ggufDeleted-3
- Teveration-1-mmproj-Q8_0.ggufDeleted-3
- pipeline.py+177-18
- teveration_engine.py+177-18
36 unmodified lines3738394041404143444546474849504243444546475253484950515552535455575657585949 unmodified lines10911011111311411511211311411511611711811912012112236 unmodified lines
## Files
A complete model is the backbone, the image file, **one** adapter and, for image-to-image and dense prediction, themmproj file.One file is the whole model, every feature included. Pick one:
| File | Size | Needed for | Content ||---|---|---|---|| [Teveration-1-backbone-PTQ1_0.gguf](https://huggingface.co/DmitrofNET/Teveration-1/resolve/main/Teveration-1-backbone-PTQ1_0.gguf?download=true) | 0.95 GB | everything | the ternary language model (1.75 bits per weight) || [Teveration-1-image-Q4_0.gguf](https://huggingface.co/DmitrofNET/Teveration-1/resolve/main/Teveration-1-image-Q4_0.gguf?download=true) | 0.72 GB | everything | image head, dense heads, decoder, CLIP text tower || [Teveration-1-adapter-Q6_mix.gguf](https://huggingface.co/DmitrofNET/Teveration-1/resolve/main/Teveration-1-adapter-Q6_mix.gguf?download=true) | 0.75 GB | **balanced** (default) | the low-rank path, 8-bit and 4-bit factors || [Teveration-1-adapter-Q4_0.gguf](https://huggingface.co/DmitrofNET/Teveration-1/resolve/main/Teveration-1-adapter-Q4_0.gguf?download=true) | 0.55 GB | small | the low-rank path, 4-bit factors || [Teveration-1-adapter-Q8_0.gguf](https://huggingface.co/DmitrofNET/Teveration-1/resolve/main/Teveration-1-adapter-Q8_0.gguf?download=true) | 1.04 GB | high | the low-rank path, 8-bit factors || [Teveration-1-mmproj-Q8_0.gguf](https://huggingface.co/DmitrofNET/Teveration-1/resolve/main/Teveration-1-mmproj-Q8_0.gguf?download=true) | 0.37 GB | image-to-image, dense prediction | the vision tower || File | Size | Quality ||---|---|---|| [Teveration-1-small.gguf](https://huggingface.co/DmitrofNET/Teveration-1/resolve/main/Teveration-1-small.gguf?download=true) | 2.59 GB | small: the low-rank path in 4 bits || [Teveration-1-balanced.gguf](https://huggingface.co/DmitrofNET/Teveration-1/resolve/main/Teveration-1-balanced.gguf?download=true) | 2.79 GB | **balanced** (default): the low-rank path in 8 and 4 bits || [Teveration-1-high.gguf](https://huggingface.co/DmitrofNET/Teveration-1/resolve/main/Teveration-1-high.gguf?download=true) | 3.08 GB | high: the low-rank path in 8 bits |
Totals with the vision tower: **2.59 GB** small, **2.79 GB** balanced, **3.08 GB** high. The original stack (Qwen3.5-4B,`jeveration.pt`, two decoders, CLIP, TA-TiTok) is 19.08 GB.The three differ only in the precision of the low-rank path. Each holds the ternary language model (1.75 bits perweight), the low-rank path, the image head, dense heads, decoder and CLIP text tower, and the vision tower. The originalstack (Qwen3.5-4B, `jeveration.pt`, two decoders, CLIP, TA-TiTok) is 19.08 GB.
You do not have to pick files by hand: every route below downloads what it needs.You do not have to download by hand: every route below fetches the file it needs. On first use the engine writes thefile's four parts to its cache (`~/.cache/teveration/parts`, the same size again on disk), because its loaders read onepart per file.
These GGUF files need the **Teveration engine**. The backbone uses PrismML's ternary tensor type and the image file isThese GGUF files need the **Teveration engine**. The backbone uses PrismML's ternary tensor type and the image part isan architecture of its own, so stock llama.cpp, Ollama and LM Studio cannot load them (and, being text-chat runtimes,could not return a picture from any model). For a chat front end, run `teveration serve` and use it as the imagebackend (OpenAI images API).49 unmodified linesEngine archives are on the [GitHub release](https://github.com/DmitrofNETDev/Teveration-1/releases).
```bashhf download DmitrofNET/Teveration-1 --include "*.gguf" --local-dir modelsteveration t2i --model models --prompt "A lighthouse on a rocky cliff under a stormy sky."teveration serve --model models --port 8188 # OpenAI images API and the AUTOMATIC1111 txt2img callhf download DmitrofNET/Teveration-1 Teveration-1-balanced.gguf --local-dir modelspython -m teveration --model models/Teveration-1-balanced.gguf t2i "A lighthouse on a rocky cliff under a stormy sky."python -m teveration --model models/Teveration-1-balanced.gguf serve --port 8188 # OpenAI images API and the AUTOMATIC1111 txt2img call```
The engine's own executable (`teveration t2i --model models/Teveration-1-balanced.gguf --prompt "..."`) reads the one-filemodels from engine version 1.0.1 on. The 1.0.0 archives take the folder that `python -m teveration download` prints.
## Where it runs
| | Status |123version https://git-lfs.github.com/spec/v1oid sha256:8794bdb5d3e6cf2b2f090ce9b3dec78281ee73488731570fa104fc0261a5b5a2size 548563968123version https://git-lfs.github.com/spec/v1oid sha256:b76c727c29773d59f1ebb963ce72d72b8fafbc62658fcfcdcb5150cad97b9a63size 746744832123version https://git-lfs.github.com/spec/v1oid sha256:b57f8099813f63ffd8ab144ecdb15b815a94882cbd6f3651945ce3163fb48a1fsize 1036151808123version https://git-lfs.github.com/spec/v1oid sha256:e723957cbd25803c796dd115f2b5adc54f87b59302d8b5fabc12bac24f1c4120size 949550112123version https://git-lfs.github.com/spec/v1oid sha256:5818516141df5311c3a29a433b54835f596bfbff4d494bd47a551ee8910a4efcsize 723575968123version https://git-lfs.github.com/spec/v1oid sha256:db939d5f9b7014137810205e91d05e5f54afd72b0b3af9d33bd7d82f7906a55dsize 36689462454 unmodified lines5556575859606162585960616263646566676869706571726768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312327723323423523623723896 unmodified lines335336337180181182338339340341342184343344345346124 unmodified lines47147247331547447547647754 unmodified lines os.replace(tmp, path)
def find_model(folder=None, vision=True, quality="balanced"): """the folder that holds the GGUF files; missing files are downloaded from Hugging Face""" names = [n for k, n in list(GGUF.items()) + [("adapter", ADAPTERS[quality])] if vision or k != "mmproj"] folder = folder or os.environ.get("TEVERATION_MODEL") if folder is None:def resolve_model(model=None, vision=True, quality="balanced"): """-> (folder with the model's parts, quality). model: a one-file model (Teveration-1-<quality>.gguf), a folder that holds one, a folder with the four parts, or None: then the one-file model of this quality is downloaded from Hugging Face.""" model = model or os.environ.get("TEVERATION_MODEL") if model and os.path.isfile(model): return unpack_single(model, vision) if model and os.path.isdir(model): names = [n for k, n in list(GGUF.items()) + [("adapter", ADAPTERS[quality])] if vision or k != "mmproj"] if all(os.path.exists(os.path.join(model, n)) for n in names): return model, quality if model is None: try: # the standard Hugging Face cache, shared with every other tool from huggingface_hub import hf_hub_download return os.path.dirname([hf_hub_download(HF_REPO, n) for n in names][0]) return unpack_single(hf_hub_download(HF_REPO, SINGLE[quality]), vision) except ImportError: folder = os.path.join(cache_dir(), "model") for name in names: path = os.path.join(folder, name) if not os.path.exists(path): _download(f"https://huggingface.co/{HF_REPO}/resolve/main/{name}", path, name) return folder model = os.path.join(cache_dir(), "model") path = os.path.join(model, SINGLE[quality]) if not os.path.exists(path): _download(f"https://huggingface.co/{HF_REPO}/resolve/main/{SINGLE[quality]}", path, SINGLE[quality]) return unpack_single(path, vision)
def find_model(folder=None, vision=True, quality="balanced"): """the folder that holds the model's parts for the engine; a missing model is downloaded from Hugging Face""" return resolve_model(folder, vision, quality)[0]
# ---- one-file models ---------------------------------------------------------------------------------------------------------# Teveration-1-<quality>.gguf holds the four parts in one GGUF: the backbone's metadata and tensors under their own names, the# other parts under a prefix (metadata "part.<part>.", tensors PART_PREFIX), and "single.<part>.*" says where each part's data is.SINGLE = {"small": "Teveration-1-small.gguf", "balanced": "Teveration-1-balanced.gguf", "high": "Teveration-1-high.gguf"}PART_PREFIX = {"backbone": "", "image": "img.", "adapter": "adp.", "mmproj": "mmp."}_SCALAR = {0: 1, 1: 1, 2: 2, 3: 2, 4: 4, 5: 4, 6: 4, 7: 1, 10: 8, 11: 8, 12: 8}
def _gguf_str(s): b = s.encode() return len(b).to_bytes(8, "little") + b
def gguf_header(path): """the header of a GGUF file: {"kv": [(key, raw type + value bytes)], "tensors": [(name, raw dims + type bytes, offset)], "data": where the tensor data starts, "align", "size", "version"}""" size, want = os.path.getsize(path), 1 << 24 while True: with open(path, "rb") as f: b = f.read(want) try: return _gguf_parse(b, size) except IndexError: if want >= size: raise ValueError(f"{path} is not a complete GGUF file") from None want *= 8
def _gguf_parse(b, size): u32 = lambda p: int.from_bytes(b[p:p + 4], "little") # noqa: E731 u64 = lambda p: int.from_bytes(b[p:p + 8], "little") # noqa: E731
def need(p): if p > len(b): raise IndexError return p
def string(p): n = u64(need(p + 8) - 8) return b[p + 8:need(p + 8 + n)].decode(), p + 8 + n
def value(p, t): if t in _SCALAR: return p + _SCALAR[t] if t == 8: return need(p + 8) + u64(p) if t != 9: raise ValueError(f"unknown GGUF value type {t}") et, n = u32(need(p + 12) - 12), u64(p + 4) p += 12 if et in _SCALAR: return p + _SCALAR[et] * n for _ in range(n): p = value(p, et) return p
if b[:4] != b"GGUF": raise ValueError("not a GGUF file") version, nt, nkv, p, kv, tensors, align = u32(4), u64(8), u64(16), 24, [], [], 32 for _ in range(nkv): key, p = string(p) end = need(value(need(p + 4), u32(p))) if key == "general.alignment": align = u32(p + 4) kv.append((key, b[p:end])) p = end for _ in range(nt): name, p = string(p) end = need(p + 4 + 8 * u32(need(p + 4) - 4) + 4 + 8) tensors.append((name, b[p:end - 8], u64(end - 8))) p = end return {"kv": kv, "tensors": tensors, "data": -(-p // align) * align, "align": align, "size": size, "version": version}
def _kv_get(h, key): for k, raw in h["kv"]: if k == key: t = int.from_bytes(raw[:4], "little") return raw[12:].decode() if t == 8 else int.from_bytes(raw[4:], "little") return None
def is_single(path): """True for a one-file model""" try: return bool(path) and os.path.isfile(path) and _kv_get(gguf_header(path), "single.version") is not None except (ValueError, OSError): return False
def _gguf_write_head(f, version, kv, tensors, align): f.write(b"GGUF" + version.to_bytes(4, "little") + len(tensors).to_bytes(8, "little") + len(kv).to_bytes(8, "little")) for key, raw in kv: f.write(_gguf_str(key) + raw) for name, raw, off in tensors: f.write(_gguf_str(name) + raw + off.to_bytes(8, "little")) f.write(b"\0" * (-f.tell() % align))
def _copy(src, dst, start, n): src.seek(start) while n > 0: chunk = src.read(min(n, 1 << 24)) if not chunk: raise ValueError("the file is shorter than its header says") dst.write(chunk) n -= len(chunk)
def unpack_single(path, vision=True): """A one-file model -> the folder with its parts as the engine loads them (written once, to the cache), and its quality.""" h = gguf_header(path) quality = _kv_get(h, "single.quality") st = os.stat(path) root = os.path.join(cache_dir(), "parts") folder = os.path.join(root, f"{os.path.basename(path)[:-5]}-{st.st_size:x}-p{st.st_mtime_ns:x}") names = dict(GGUF, adapter=ADAPTERS[quality]) todo = [p for p in PART_PREFIX if (vision or p != "mmproj") and not os.path.exists(os.path.join(folder, names[p]))] if not todo: return folder, quality if os.path.isdir(root): # parts of an older copy of the same file import shutil for d in os.listdir(root): if d.startswith(os.path.basename(path)[:-5] + "-") and "-p" in d and os.path.join(root, d) != folder: shutil.rmtree(os.path.join(root, d), ignore_errors=True) os.makedirs(folder, exist_ok=True) print(f"teveration: unpacking {os.path.basename(path)} (once)", file=sys.stderr, flush=True) others = tuple(v for v in PART_PREFIX.values() if v) with open(path, "rb") as src: for part in todo: pre, kpre = PART_PREFIX[part], f"part.{part}." if part == "backbone": kv = [(k, r) for k, r in h["kv"] if not k.startswith(("part.", "single."))] tensors = [t for t in h["tensors"] if not t[0].startswith(others)] else: kv = [(k[len(kpre):], r) for k, r in h["kv"] if k.startswith(kpre)] tensors = [t for t in h["tensors"] if t[0].startswith(pre)] start, size = _kv_get(h, f"single.{part}.offset"), _kv_get(h, f"single.{part}.size") tmp = os.path.join(folder, names[part] + ".part") with open(tmp, "wb") as f: _gguf_write_head(f, h["version"], kv, [(n[len(pre):], r, o - start) for n, r, o in tensors], h["align"]) _copy(src, f, h["data"] + start, size) os.replace(tmp, os.path.join(folder, names[part])) return folder, quality
def local_model(path): """path if it is a folder that already holds the GGUF files (a clone or snapshot of the repository), else None""" return path if path and os.path.isdir(path) and os.path.exists(os.path.join(path, GGUF["backbone"])) else None if path and os.path.isdir(path) and (os.path.exists(os.path.join(path, GGUF["backbone"])) or any(os.path.exists(os.path.join(path, n)) for n in SINGLE.values())): return path return path if path and os.path.isfile(path) and path.endswith(".gguf") else None
def _lib_name():96 unmodified lines
class Teveration: def __init__(self, model=None, device="auto", threads=0, vision=True, quality="balanced", lib=None): """model: folder with the GGUF files (default: download to the cache); device: auto, cuda, vulkan or cpu; vision: load the vision tower too (needed for image_to_image and dense_predict, about 0.4 GB); quality: small (2.6 GB in total), balanced (2.8 GB) or high (3.1 GB): the precision of the low-rank path""" """model: a Teveration-1-<quality>.gguf file or a folder with one (default: download to the cache); device: auto, cuda, vulkan or cpu; vision: load the vision tower too (needed for image_to_image and dense_predict, about 0.4 GB); quality: small (2.6 GB), balanced (2.8 GB) or high (3.1 GB): the precision of the low-rank path. A file given as model decides the quality itself.""" assert quality in ADAPTERS, f"quality must be one of {tuple(ADAPTERS)}" self.folder = find_model(model, vision, quality) self.folder, quality = resolve_model(model, vision, quality) self.quality = quality self.lib = L = self._open(lib, device) c, u8p, i32p, f32p = ctypes.c_char_p, ctypes.POINTER(ctypes.c_uint8), ctypes.POINTER(ctypes.c_int32), ctypes.POINTER(ctypes.c_float)124 unmodified lines
def info(): return json.dumps({"version": VERSION, "engine": engine_variant(), "cache": cache_dir(), "files": GGUF, "adapters": ADAPTERS}, indent=1) return json.dumps({"version": VERSION, "engine": engine_variant(), "cache": cache_dir(), "files": SINGLE}, indent=1)
47 unmodified lines484950515253545551525354555657585960616263586465606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242257022622722822923023196 unmodified lines328329330173174175331332333334335177336337338339124 unmodified lines46446546630846747 unmodified lines os.replace(tmp, path)
def find_model(folder=None, vision=True, quality="balanced"): """the folder that holds the GGUF files; missing files are downloaded from Hugging Face""" names = [n for k, n in list(GGUF.items()) + [("adapter", ADAPTERS[quality])] if vision or k != "mmproj"] folder = folder or os.environ.get("TEVERATION_MODEL") if folder is None:def resolve_model(model=None, vision=True, quality="balanced"): """-> (folder with the model's parts, quality). model: a one-file model (Teveration-1-<quality>.gguf), a folder that holds one, a folder with the four parts, or None: then the one-file model of this quality is downloaded from Hugging Face.""" model = model or os.environ.get("TEVERATION_MODEL") if model and os.path.isfile(model): return unpack_single(model, vision) if model and os.path.isdir(model): names = [n for k, n in list(GGUF.items()) + [("adapter", ADAPTERS[quality])] if vision or k != "mmproj"] if all(os.path.exists(os.path.join(model, n)) for n in names): return model, quality if model is None: try: # the standard Hugging Face cache, shared with every other tool from huggingface_hub import hf_hub_download return os.path.dirname([hf_hub_download(HF_REPO, n) for n in names][0]) return unpack_single(hf_hub_download(HF_REPO, SINGLE[quality]), vision) except ImportError: folder = os.path.join(cache_dir(), "model") for name in names: path = os.path.join(folder, name) if not os.path.exists(path): _download(f"https://huggingface.co/{HF_REPO}/resolve/main/{name}", path, name) return folder model = os.path.join(cache_dir(), "model") path = os.path.join(model, SINGLE[quality]) if not os.path.exists(path): _download(f"https://huggingface.co/{HF_REPO}/resolve/main/{SINGLE[quality]}", path, SINGLE[quality]) return unpack_single(path, vision)
def find_model(folder=None, vision=True, quality="balanced"): """the folder that holds the model's parts for the engine; a missing model is downloaded from Hugging Face""" return resolve_model(folder, vision, quality)[0]
# ---- one-file models ---------------------------------------------------------------------------------------------------------# Teveration-1-<quality>.gguf holds the four parts in one GGUF: the backbone's metadata and tensors under their own names, the# other parts under a prefix (metadata "part.<part>.", tensors PART_PREFIX), and "single.<part>.*" says where each part's data is.SINGLE = {"small": "Teveration-1-small.gguf", "balanced": "Teveration-1-balanced.gguf", "high": "Teveration-1-high.gguf"}PART_PREFIX = {"backbone": "", "image": "img.", "adapter": "adp.", "mmproj": "mmp."}_SCALAR = {0: 1, 1: 1, 2: 2, 3: 2, 4: 4, 5: 4, 6: 4, 7: 1, 10: 8, 11: 8, 12: 8}
def _gguf_str(s): b = s.encode() return len(b).to_bytes(8, "little") + b
def gguf_header(path): """the header of a GGUF file: {"kv": [(key, raw type + value bytes)], "tensors": [(name, raw dims + type bytes, offset)], "data": where the tensor data starts, "align", "size", "version"}""" size, want = os.path.getsize(path), 1 << 24 while True: with open(path, "rb") as f: b = f.read(want) try: return _gguf_parse(b, size) except IndexError: if want >= size: raise ValueError(f"{path} is not a complete GGUF file") from None want *= 8
def _gguf_parse(b, size): u32 = lambda p: int.from_bytes(b[p:p + 4], "little") # noqa: E731 u64 = lambda p: int.from_bytes(b[p:p + 8], "little") # noqa: E731
def need(p): if p > len(b): raise IndexError return p
def string(p): n = u64(need(p + 8) - 8) return b[p + 8:need(p + 8 + n)].decode(), p + 8 + n
def value(p, t): if t in _SCALAR: return p + _SCALAR[t] if t == 8: return need(p + 8) + u64(p) if t != 9: raise ValueError(f"unknown GGUF value type {t}") et, n = u32(need(p + 12) - 12), u64(p + 4) p += 12 if et in _SCALAR: return p + _SCALAR[et] * n for _ in range(n): p = value(p, et) return p
if b[:4] != b"GGUF": raise ValueError("not a GGUF file") version, nt, nkv, p, kv, tensors, align = u32(4), u64(8), u64(16), 24, [], [], 32 for _ in range(nkv): key, p = string(p) end = need(value(need(p + 4), u32(p))) if key == "general.alignment": align = u32(p + 4) kv.append((key, b[p:end])) p = end for _ in range(nt): name, p = string(p) end = need(p + 4 + 8 * u32(need(p + 4) - 4) + 4 + 8) tensors.append((name, b[p:end - 8], u64(end - 8))) p = end return {"kv": kv, "tensors": tensors, "data": -(-p // align) * align, "align": align, "size": size, "version": version}
def _kv_get(h, key): for k, raw in h["kv"]: if k == key: t = int.from_bytes(raw[:4], "little") return raw[12:].decode() if t == 8 else int.from_bytes(raw[4:], "little") return None
def is_single(path): """True for a one-file model""" try: return bool(path) and os.path.isfile(path) and _kv_get(gguf_header(path), "single.version") is not None except (ValueError, OSError): return False
def _gguf_write_head(f, version, kv, tensors, align): f.write(b"GGUF" + version.to_bytes(4, "little") + len(tensors).to_bytes(8, "little") + len(kv).to_bytes(8, "little")) for key, raw in kv: f.write(_gguf_str(key) + raw) for name, raw, off in tensors: f.write(_gguf_str(name) + raw + off.to_bytes(8, "little")) f.write(b"\0" * (-f.tell() % align))
def _copy(src, dst, start, n): src.seek(start) while n > 0: chunk = src.read(min(n, 1 << 24)) if not chunk: raise ValueError("the file is shorter than its header says") dst.write(chunk) n -= len(chunk)
def unpack_single(path, vision=True): """A one-file model -> the folder with its parts as the engine loads them (written once, to the cache), and its quality.""" h = gguf_header(path) quality = _kv_get(h, "single.quality") st = os.stat(path) root = os.path.join(cache_dir(), "parts") folder = os.path.join(root, f"{os.path.basename(path)[:-5]}-{st.st_size:x}-p{st.st_mtime_ns:x}") names = dict(GGUF, adapter=ADAPTERS[quality]) todo = [p for p in PART_PREFIX if (vision or p != "mmproj") and not os.path.exists(os.path.join(folder, names[p]))] if not todo: return folder, quality if os.path.isdir(root): # parts of an older copy of the same file import shutil for d in os.listdir(root): if d.startswith(os.path.basename(path)[:-5] + "-") and "-p" in d and os.path.join(root, d) != folder: shutil.rmtree(os.path.join(root, d), ignore_errors=True) os.makedirs(folder, exist_ok=True) print(f"teveration: unpacking {os.path.basename(path)} (once)", file=sys.stderr, flush=True) others = tuple(v for v in PART_PREFIX.values() if v) with open(path, "rb") as src: for part in todo: pre, kpre = PART_PREFIX[part], f"part.{part}." if part == "backbone": kv = [(k, r) for k, r in h["kv"] if not k.startswith(("part.", "single."))] tensors = [t for t in h["tensors"] if not t[0].startswith(others)] else: kv = [(k[len(kpre):], r) for k, r in h["kv"] if k.startswith(kpre)] tensors = [t for t in h["tensors"] if t[0].startswith(pre)] start, size = _kv_get(h, f"single.{part}.offset"), _kv_get(h, f"single.{part}.size") tmp = os.path.join(folder, names[part] + ".part") with open(tmp, "wb") as f: _gguf_write_head(f, h["version"], kv, [(n[len(pre):], r, o - start) for n, r, o in tensors], h["align"]) _copy(src, f, h["data"] + start, size) os.replace(tmp, os.path.join(folder, names[part])) return folder, quality
def local_model(path): """path if it is a folder that already holds the GGUF files (a clone or snapshot of the repository), else None""" return path if path and os.path.isdir(path) and os.path.exists(os.path.join(path, GGUF["backbone"])) else None if path and os.path.isdir(path) and (os.path.exists(os.path.join(path, GGUF["backbone"])) or any(os.path.exists(os.path.join(path, n)) for n in SINGLE.values())): return path return path if path and os.path.isfile(path) and path.endswith(".gguf") else None
def _lib_name():96 unmodified lines
class Teveration: def __init__(self, model=None, device="auto", threads=0, vision=True, quality="balanced", lib=None): """model: folder with the GGUF files (default: download to the cache); device: auto, cuda, vulkan or cpu; vision: load the vision tower too (needed for image_to_image and dense_predict, about 0.4 GB); quality: small (2.6 GB in total), balanced (2.8 GB) or high (3.1 GB): the precision of the low-rank path""" """model: a Teveration-1-<quality>.gguf file or a folder with one (default: download to the cache); device: auto, cuda, vulkan or cpu; vision: load the vision tower too (needed for image_to_image and dense_predict, about 0.4 GB); quality: small (2.6 GB), balanced (2.8 GB) or high (3.1 GB): the precision of the low-rank path. A file given as model decides the quality itself.""" assert quality in ADAPTERS, f"quality must be one of {tuple(ADAPTERS)}" self.folder = find_model(model, vision, quality) self.folder, quality = resolve_model(model, vision, quality) self.quality = quality self.lib = L = self._open(lib, device) c, u8p, i32p, f32p = ctypes.c_char_p, ctypes.POINTER(ctypes.c_uint8), ctypes.POINTER(ctypes.c_int32), ctypes.POINTER(ctypes.c_float)124 unmodified lines
def info(): return json.dumps({"version": VERSION, "engine": engine_variant(), "cache": cache_dir(), "files": GGUF, "adapters": ADAPTERS}, indent=1) return json.dumps({"version": VERSION, "engine": engine_variant(), "cache": cache_dir(), "files": SINGLE}, indent=1)README.md+19-17
Teveration-1-adapter-Q4_0.ggufDeleted-3
Teveration-1-adapter-Q6_mix.ggufDeleted-3
Teveration-1-adapter-Q8_0.ggufDeleted-3
Teveration-1-backbone-PTQ1_0.ggufDeleted-3
Teveration-1-image-Q4_0.ggufDeleted-3
Teveration-1-mmproj-Q8_0.ggufDeleted-3
pipeline.py+177-18
teveration_engine.py+177-18