Text Generation
Transformers
halt_cot
chain-of-thought
reasoning
early-stopping
entropy
inference-optimization
Instructions to use yass4/halt-cot with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yass4/halt-cot with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yass4/halt-cot")# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("yass4/halt-cot", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use yass4/halt-cot with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yass4/halt-cot" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yass4/halt-cot", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/yass4/halt-cot
- SGLang
How to use yass4/halt-cot 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 "yass4/halt-cot" \ --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": "yass4/halt-cot", "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 "yass4/halt-cot" \ --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": "yass4/halt-cot", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use yass4/halt-cot with Docker Model Runner:
docker model run hf.co/yass4/halt-cot
Fetch published config.json from Hub on load (enables download tracking)
Browse files
halt_cot/transformers_backend.py
CHANGED
|
@@ -2,8 +2,9 @@
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
-
from dataclasses import replace
|
| 6 |
-
import
|
|
|
|
| 7 |
from typing import Sequence
|
| 8 |
|
| 9 |
from .core import (
|
|
@@ -19,6 +20,53 @@ from .core import (
|
|
| 19 |
)
|
| 20 |
|
| 21 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
class TextStopCriteria:
|
| 23 |
"""Transformers stopping criterion that halts when generated text hits a marker."""
|
| 24 |
|
|
@@ -74,6 +122,9 @@ class HaltCoTForCausalLM:
|
|
| 74 |
|
| 75 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 76 |
|
|
|
|
|
|
|
|
|
|
| 77 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 78 |
model_id,
|
| 79 |
trust_remote_code=trust_remote_code,
|
|
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
+
from dataclasses import fields, replace
|
| 6 |
+
import json
|
| 7 |
+
import os
|
| 8 |
from typing import Sequence
|
| 9 |
|
| 10 |
from .core import (
|
|
|
|
| 20 |
)
|
| 21 |
|
| 22 |
|
| 23 |
+
HALT_COT_CONFIG_REPO = os.getenv("HALT_COT_CONFIG_REPO", "yass4/halt-cot")
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def load_config_from_hub(
|
| 27 |
+
repo_id: str = HALT_COT_CONFIG_REPO,
|
| 28 |
+
*,
|
| 29 |
+
filename: str = "config.json",
|
| 30 |
+
) -> HaltCoTConfig | None:
|
| 31 |
+
"""Fetch the published HALT-CoT defaults from the Hub.
|
| 32 |
+
|
| 33 |
+
Downloading ``config.json`` through the Hub also lets Hugging Face count
|
| 34 |
+
real usage of the method. Any failure (offline, missing repo, malformed
|
| 35 |
+
file) returns ``None`` so callers fall back to the built-in defaults and a
|
| 36 |
+
run is never blocked.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
try:
|
| 40 |
+
from huggingface_hub import hf_hub_download
|
| 41 |
+
|
| 42 |
+
path = hf_hub_download(repo_id=repo_id, filename=filename)
|
| 43 |
+
payload = json.loads(open(path, encoding="utf-8").read())
|
| 44 |
+
except Exception:
|
| 45 |
+
return None
|
| 46 |
+
|
| 47 |
+
values = payload.get("halt_cot", payload)
|
| 48 |
+
if not isinstance(values, dict):
|
| 49 |
+
return None
|
| 50 |
+
|
| 51 |
+
defaults = HaltCoTConfig()
|
| 52 |
+
tuple_fields = {
|
| 53 |
+
f.name for f in fields(HaltCoTConfig)
|
| 54 |
+
if isinstance(getattr(defaults, f.name), tuple)
|
| 55 |
+
}
|
| 56 |
+
kwargs = {}
|
| 57 |
+
for field in fields(HaltCoTConfig):
|
| 58 |
+
if field.name not in values:
|
| 59 |
+
continue
|
| 60 |
+
value = values[field.name]
|
| 61 |
+
if field.name in tuple_fields and isinstance(value, list):
|
| 62 |
+
value = tuple(value)
|
| 63 |
+
kwargs[field.name] = value
|
| 64 |
+
try:
|
| 65 |
+
return HaltCoTConfig(**kwargs)
|
| 66 |
+
except (TypeError, ValueError):
|
| 67 |
+
return None
|
| 68 |
+
|
| 69 |
+
|
| 70 |
class TextStopCriteria:
|
| 71 |
"""Transformers stopping criterion that halts when generated text hits a marker."""
|
| 72 |
|
|
|
|
| 122 |
|
| 123 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 124 |
|
| 125 |
+
if config is None:
|
| 126 |
+
config = load_config_from_hub()
|
| 127 |
+
|
| 128 |
tokenizer = AutoTokenizer.from_pretrained(
|
| 129 |
model_id,
|
| 130 |
trust_remote_code=trust_remote_code,
|