Text Generation
Transformers
PyTorch
English
experimental
research
bit-level
transformer
reversible
safety
telemetry
language-modeling
Instructions to use WCNegentropy/BitTransformerLM with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use WCNegentropy/BitTransformerLM with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="WCNegentropy/BitTransformerLM")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("WCNegentropy/BitTransformerLM", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use WCNegentropy/BitTransformerLM with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "WCNegentropy/BitTransformerLM" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "WCNegentropy/BitTransformerLM", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/WCNegentropy/BitTransformerLM
- SGLang
How to use WCNegentropy/BitTransformerLM 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 "WCNegentropy/BitTransformerLM" \ --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": "WCNegentropy/BitTransformerLM", "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 "WCNegentropy/BitTransformerLM" \ --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": "WCNegentropy/BitTransformerLM", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use WCNegentropy/BitTransformerLM with Docker Model Runner:
docker model run hf.co/WCNegentropy/BitTransformerLM
| from __future__ import annotations | |
| import gzip | |
| import os | |
| import shutil | |
| import tempfile | |
| from typing import Optional | |
| import torch | |
| from huggingface_hub import HfApi, hf_hub_download, login | |
| REPO_ID = "WCNegentropy/BitTransformerLM" | |
| FILENAME = "model.pt.gz" | |
| def hf_login(token: Optional[str] = None) -> None: | |
| """Authenticate with Hugging Face. | |
| The ``token`` may be provided directly or via the ``HF_TOKEN`` environment | |
| variable. If omitted entirely, the library will attempt an interactive login. | |
| """ | |
| login(token=token) | |
| def save_checkpoint( | |
| model: torch.nn.Module, | |
| *, | |
| repo_id: str = REPO_ID, | |
| filename: str = FILENAME, | |
| ) -> None: | |
| """Upload the model weights to ``repo_id`` under ``filename``. | |
| The file within the repository is overwritten each time to avoid | |
| accumulating checkpoints. | |
| """ | |
| with tempfile.TemporaryDirectory() as tmp: | |
| tmp_pt = os.path.join(tmp, "model.pt") | |
| tmp_gz = os.path.join(tmp, filename) | |
| torch.save(model.state_dict(), tmp_pt) | |
| with open(tmp_pt, "rb") as src, gzip.open(tmp_gz, "wb") as dst: | |
| dst.write(src.read()) | |
| HfApi().upload_file( | |
| path_or_fileobj=tmp_gz, | |
| path_in_repo=f"checkpoints/{filename}", | |
| repo_id=repo_id, | |
| repo_type="model", | |
| overwrite=True, | |
| ) | |
| def download_checkpoint( | |
| dest_path: str, | |
| *, | |
| repo_id: str = REPO_ID, | |
| filename: str = FILENAME, | |
| ) -> bool: | |
| """Download the latest checkpoint to ``dest_path``. | |
| Returns ``True`` if the checkpoint was successfully retrieved. | |
| """ | |
| try: | |
| buf = hf_hub_download( | |
| repo_id, | |
| f"checkpoints/{filename}", | |
| repo_type="model", | |
| force_download=True, | |
| ) | |
| except Exception as exc: # pragma: no cover - network errors | |
| print("Failed to download checkpoint", exc) | |
| return False | |
| os.makedirs(os.path.dirname(dest_path), exist_ok=True) | |
| shutil.copyfile(buf, dest_path) | |
| return True | |
| __all__ = ["hf_login", "save_checkpoint", "download_checkpoint"] | |