Text Generation
Transformers
Safetensors
PyTorch
Nepali
supernova_transformer_v2
supernova
causal-lm
transformer
Instructions to use Supernova11c/Supernova-Transformer-V2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Supernova11c/Supernova-Transformer-V2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Supernova11c/Supernova-Transformer-V2")# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Supernova11c/Supernova-Transformer-V2", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Supernova11c/Supernova-Transformer-V2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Supernova11c/Supernova-Transformer-V2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Supernova11c/Supernova-Transformer-V2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Supernova11c/Supernova-Transformer-V2
- SGLang
How to use Supernova11c/Supernova-Transformer-V2 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 "Supernova11c/Supernova-Transformer-V2" \ --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": "Supernova11c/Supernova-Transformer-V2", "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 "Supernova11c/Supernova-Transformer-V2" \ --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": "Supernova11c/Supernova-Transformer-V2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Supernova11c/Supernova-Transformer-V2 with Docker Model Runner:
docker model run hf.co/Supernova11c/Supernova-Transformer-V2
Download tokenization_supernova.py from Supernova11c/Supernova-Transformer-V2: direct link, hf CLI and curl.
- Browser
- Download file 2.9 kB
-
https://huggingface.co/Supernova11c/Supernova-Transformer-V2/resolve/main/tokenization_supernova.py
- Command line
-
hf download hf://Supernova11c/Supernova-Transformer-V2/tokenization_supernova.py
-
curl -L -o tokenization_supernova.py https://huggingface.co/Supernova11c/Supernova-Transformer-V2/resolve/main/tokenization_supernova.py
2.9 kB
| import json | |
| from pathlib import Path | |
| from transformers import PreTrainedTokenizer | |
| class SupernovaTokenizer(PreTrainedTokenizer): | |
| vocab_files_names = { | |
| "vocab_file": "vocab.json" | |
| } | |
| model_input_names = [ | |
| "input_ids", | |
| "attention_mask", | |
| ] | |
| def __init__( | |
| self, | |
| vocab_file, | |
| bos_token="<BOS>", | |
| eos_token="<EOS>", | |
| pad_token="<PAD>", | |
| user_token="<USER>", | |
| assistant_token="<ASSISTANT>", | |
| **kwargs, | |
| ): | |
| with open( | |
| vocab_file, | |
| "r", | |
| encoding="utf-8", | |
| ) as f: | |
| vocab = json.load(f) | |
| self.vocab = { | |
| str(token): int(idx) | |
| for token, idx in vocab.items() | |
| } | |
| self.ids_to_tokens = { | |
| int(idx): str(token) | |
| for token, idx in self.vocab.items() | |
| } | |
| self.user_token = user_token | |
| self.assistant_token = assistant_token | |
| super().__init__( | |
| bos_token=bos_token, | |
| eos_token=eos_token, | |
| pad_token=pad_token, | |
| **kwargs, | |
| ) | |
| def vocab_size(self): | |
| return len(self.vocab) | |
| def get_vocab(self): | |
| return dict(self.vocab) | |
| def _tokenize(self, text, **kwargs): | |
| return list(text) | |
| def _convert_token_to_id(self, token): | |
| if token not in self.vocab: | |
| raise ValueError( | |
| f"Unknown character/token: {token!r}" | |
| ) | |
| return self.vocab[token] | |
| def _convert_id_to_token(self, index): | |
| index = int(index) | |
| if index not in self.ids_to_tokens: | |
| raise ValueError( | |
| f"Unknown token id: {index}" | |
| ) | |
| return self.ids_to_tokens[index] | |
| def convert_tokens_to_string(self, tokens): | |
| return "".join(tokens) | |
| def build_inputs_with_special_tokens( | |
| self, | |
| token_ids_0, | |
| token_ids_1=None, | |
| ): | |
| result = [self.bos_token_id] | |
| result += list(token_ids_0) | |
| if token_ids_1 is not None: | |
| result += list(token_ids_1) | |
| result += [self.eos_token_id] | |
| return result | |
| def save_vocabulary( | |
| self, | |
| save_directory, | |
| filename_prefix=None, | |
| ): | |
| save_directory = Path(save_directory) | |
| save_directory.mkdir( | |
| parents=True, | |
| exist_ok=True, | |
| ) | |
| filename = "vocab.json" | |
| if filename_prefix: | |
| filename = ( | |
| f"{filename_prefix}-vocab.json" | |
| ) | |
| path = save_directory / filename | |
| with open( | |
| path, | |
| "w", | |
| encoding="utf-8", | |
| ) as f: | |
| json.dump( | |
| self.vocab, | |
| f, | |
| ensure_ascii=False, | |
| indent=2, | |
| ) | |
| return (str(path),) | |