Instructions to use Jonnester/Purrence-3M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Jonnester/Purrence-3M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Jonnester/Purrence-3M", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Jonnester/Purrence-3M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Jonnester/Purrence-3M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Jonnester/Purrence-3M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Jonnester/Purrence-3M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Jonnester/Purrence-3M
- SGLang
How to use Jonnester/Purrence-3M 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 "Jonnester/Purrence-3M" \ --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": "Jonnester/Purrence-3M", "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 "Jonnester/Purrence-3M" \ --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": "Jonnester/Purrence-3M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Jonnester/Purrence-3M with Docker Model Runner:
docker model run hf.co/Jonnester/Purrence-3M
Download tokenization_purrence.py from Jonnester/Purrence-3M: direct link, hf CLI and curl.
- Browser
- Download file 2.52 kB
-
https://huggingface.co/Jonnester/Purrence-3M/resolve/main/tokenization_purrence.py
- Command line
-
hf download hf://Jonnester/Purrence-3M/tokenization_purrence.py
-
curl -L -o tokenization_purrence.py https://huggingface.co/Jonnester/Purrence-3M/resolve/main/tokenization_purrence.py
2.52 kB
| """Transformers adapter preserving literal text and the original byte BPE.""" | |
| from pathlib import Path | |
| from transformers import PreTrainedTokenizer | |
| from .purrence_core import Sub3MTokenizer | |
| class PurrenceTokenizer(PreTrainedTokenizer): | |
| vocab_files_names = {"vocab_file": "tokenizer/ordinary-tokenizer.json", | |
| "artifact_file": "tokenizer/artifact.json"} | |
| model_input_names = ["input_ids", "attention_mask"] | |
| def __init__(self, vocab_file, artifact_file, **kwargs): | |
| self.native = Sub3MTokenizer(Path(artifact_file).parent) | |
| self.vocab_file = vocab_file | |
| self.artifact_file = artifact_file | |
| self.vocab = self.native.backend.get_vocab() | |
| self.vocab["<|endoftext|>"] = 2047 | |
| self.reverse_vocab = {v: k for k, v in self.vocab.items()} | |
| kwargs.setdefault("bos_token", "<|endoftext|>") | |
| kwargs.setdefault("eos_token", "<|endoftext|>") | |
| kwargs.setdefault("pad_token", "<|endoftext|>") | |
| kwargs.setdefault("model_max_length", 8192) | |
| kwargs["split_special_tokens"] = True | |
| kwargs["clean_up_tokenization_spaces"] = False | |
| super().__init__(**kwargs) | |
| def vocab_size(self): | |
| return 2048 | |
| def get_vocab(self): | |
| return dict(self.vocab) | |
| def _tokenize(self, text, **kwargs): | |
| return [self.reverse_vocab[i] for i in self.native.encode(text)] | |
| def _convert_token_to_id(self, token): | |
| return self.vocab[token] | |
| def _convert_id_to_token(self, index): | |
| return self.reverse_vocab[index] | |
| def convert_tokens_to_string(self, tokens): | |
| return self.native.decode([self.vocab[t] for t in tokens]) | |
| def _decode(self, token_ids, skip_special_tokens=False, **kwargs): | |
| if isinstance(token_ids, int): | |
| token_ids = [token_ids] | |
| return self.native.decode([int(i) for i in token_ids], skip_boundaries=skip_special_tokens) | |
| def save_vocabulary(self, save_directory, filename_prefix=None): | |
| import shutil | |
| if filename_prefix: | |
| raise ValueError("This fixed tokenizer uses canonical filenames") | |
| target = Path(save_directory) / "tokenizer" | |
| target.mkdir(parents=True, exist_ok=True) | |
| paths = [] | |
| for source in [self.vocab_file, self.artifact_file]: | |
| dest = target / Path(source).name | |
| if Path(source).resolve() != dest.resolve(): | |
| shutil.copyfile(source, dest) | |
| paths.append(str(dest)) | |
| return tuple(paths) | |