Text Generation
Transformers
Safetensors
taonet
trust-remote-code
sentencepiece
custom-architecture
custom_code
Instructions to use TaoTern/TaoNet-mini-A2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use TaoTern/TaoNet-mini-A2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="TaoTern/TaoNet-mini-A2", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("TaoTern/TaoNet-mini-A2", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use TaoTern/TaoNet-mini-A2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "TaoTern/TaoNet-mini-A2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "TaoTern/TaoNet-mini-A2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/TaoTern/TaoNet-mini-A2
- SGLang
How to use TaoTern/TaoNet-mini-A2 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 "TaoTern/TaoNet-mini-A2" \ --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": "TaoTern/TaoNet-mini-A2", "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 "TaoTern/TaoNet-mini-A2" \ --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": "TaoTern/TaoNet-mini-A2", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use TaoTern/TaoNet-mini-A2 with Docker Model Runner:
docker model run hf.co/TaoTern/TaoNet-mini-A2
Upload folder using huggingface_hub
Browse files- export_to_hf.py +41 -0
- modeling_taonet.py +6 -2
- taonet_model.py +6 -2
- tokenization_taonet.py +6 -0
- tokenizer_config.json +5 -79
export_to_hf.py
CHANGED
|
@@ -26,6 +26,46 @@ def infer_special_token_paths(repo_dir):
|
|
| 26 |
return repo_dir / "tokenizer" / "tokenizer.model", subdir_metadata, repo_dir / "tokenizer" / "tokenizer.vocab"
|
| 27 |
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
def main():
|
| 30 |
import torch
|
| 31 |
|
|
@@ -69,6 +109,7 @@ def main():
|
|
| 69 |
special_tokens_file=str(metadata_path),
|
| 70 |
)
|
| 71 |
tokenizer.save_pretrained(repo_dir)
|
|
|
|
| 72 |
|
| 73 |
shutil.copyfile(metadata_model_path, repo_dir / "tokenizer.model")
|
| 74 |
shutil.copyfile(metadata_path, repo_dir / "tokenizer.special_tokens.json")
|
|
|
|
| 26 |
return repo_dir / "tokenizer" / "tokenizer.model", subdir_metadata, repo_dir / "tokenizer" / "tokenizer.vocab"
|
| 27 |
|
| 28 |
|
| 29 |
+
def write_clean_tokenizer_metadata(repo_dir, special_tokens):
|
| 30 |
+
tokenizer_config = {
|
| 31 |
+
"backend": "custom",
|
| 32 |
+
"bos_token": "<BOS>",
|
| 33 |
+
"eos_token": "<EOS>",
|
| 34 |
+
"unk_token": "<UNK>",
|
| 35 |
+
"pad_token": "<PAD>",
|
| 36 |
+
"tokenizer_class": "TaoNetTokenizer",
|
| 37 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 38 |
+
"extra_special_tokens": [
|
| 39 |
+
token
|
| 40 |
+
for token in special_tokens
|
| 41 |
+
if token not in {"<UNK>", "<BOS>", "<EOS>", "<PAD>"}
|
| 42 |
+
],
|
| 43 |
+
}
|
| 44 |
+
special_tokens_map = {
|
| 45 |
+
"unk_token": "<UNK>",
|
| 46 |
+
"bos_token": "<BOS>",
|
| 47 |
+
"eos_token": "<EOS>",
|
| 48 |
+
"pad_token": "<PAD>",
|
| 49 |
+
"additional_special_tokens": [
|
| 50 |
+
token
|
| 51 |
+
for token in special_tokens
|
| 52 |
+
if token not in {"<UNK>", "<BOS>", "<EOS>", "<PAD>"}
|
| 53 |
+
],
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
with open(repo_dir / "tokenizer_config.json", "w", encoding="utf-8") as handle:
|
| 57 |
+
json.dump(tokenizer_config, handle, indent=2)
|
| 58 |
+
handle.write("\n")
|
| 59 |
+
|
| 60 |
+
with open(repo_dir / "special_tokens_map.json", "w", encoding="utf-8") as handle:
|
| 61 |
+
json.dump(special_tokens_map, handle, indent=2)
|
| 62 |
+
handle.write("\n")
|
| 63 |
+
|
| 64 |
+
added_tokens_path = repo_dir / "added_tokens.json"
|
| 65 |
+
if added_tokens_path.exists():
|
| 66 |
+
added_tokens_path.unlink()
|
| 67 |
+
|
| 68 |
+
|
| 69 |
def main():
|
| 70 |
import torch
|
| 71 |
|
|
|
|
| 109 |
special_tokens_file=str(metadata_path),
|
| 110 |
)
|
| 111 |
tokenizer.save_pretrained(repo_dir)
|
| 112 |
+
write_clean_tokenizer_metadata(repo_dir, metadata.get("configured_special_tokens", []))
|
| 113 |
|
| 114 |
shutil.copyfile(metadata_model_path, repo_dir / "tokenizer.model")
|
| 115 |
shutil.copyfile(metadata_path, repo_dir / "tokenizer.special_tokens.json")
|
modeling_taonet.py
CHANGED
|
@@ -4,8 +4,12 @@ from torch import nn
|
|
| 4 |
from transformers import GenerationMixin, PreTrainedModel
|
| 5 |
from transformers.modeling_outputs import CausalLMOutput
|
| 6 |
|
| 7 |
-
|
| 8 |
-
from .
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
|
| 11 |
class TaoNetForCausalLM(PreTrainedModel, GenerationMixin):
|
|
|
|
| 4 |
from transformers import GenerationMixin, PreTrainedModel
|
| 5 |
from transformers.modeling_outputs import CausalLMOutput
|
| 6 |
|
| 7 |
+
try:
|
| 8 |
+
from .configuration_taonet import TaoNetConfig
|
| 9 |
+
from .taonet_model import SimpleLLM, build_runtime_config
|
| 10 |
+
except ImportError:
|
| 11 |
+
from configuration_taonet import TaoNetConfig
|
| 12 |
+
from taonet_model import SimpleLLM, build_runtime_config
|
| 13 |
|
| 14 |
|
| 15 |
class TaoNetForCausalLM(PreTrainedModel, GenerationMixin):
|
taonet_model.py
CHANGED
|
@@ -6,8 +6,12 @@ import torch
|
|
| 6 |
import torch.nn as nn
|
| 7 |
import torch.nn.functional as F
|
| 8 |
|
| 9 |
-
|
| 10 |
-
from .
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
|
| 13 |
class SimpleLLM(nn.Module):
|
|
|
|
| 6 |
import torch.nn as nn
|
| 7 |
import torch.nn.functional as F
|
| 8 |
|
| 9 |
+
try:
|
| 10 |
+
from .embeddings import FactorizedEmbedding
|
| 11 |
+
from .mla_components import AttentionBlock
|
| 12 |
+
except ImportError:
|
| 13 |
+
from embeddings import FactorizedEmbedding
|
| 14 |
+
from mla_components import AttentionBlock
|
| 15 |
|
| 16 |
|
| 17 |
class SimpleLLM(nn.Module):
|
tokenization_taonet.py
CHANGED
|
@@ -43,6 +43,9 @@ class TaoNetTokenizer(PreTrainedTokenizer):
|
|
| 43 |
str(token): int(token_id) for token, token_id in metadata.get("special_tokens", {}).items()
|
| 44 |
}
|
| 45 |
configured_special_tokens = [str(token) for token in metadata.get("configured_special_tokens", [])]
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
merged_additional_tokens = list(additional_special_tokens or [])
|
| 48 |
for token in configured_special_tokens:
|
|
@@ -64,6 +67,7 @@ class TaoNetTokenizer(PreTrainedTokenizer):
|
|
| 64 |
|
| 65 |
def get_vocab(self):
|
| 66 |
vocab = {self.sp_model.id_to_piece(i): i for i in range(self.vocab_size)}
|
|
|
|
| 67 |
vocab.update(self.added_tokens_encoder)
|
| 68 |
return vocab
|
| 69 |
|
|
@@ -79,6 +83,8 @@ class TaoNetTokenizer(PreTrainedTokenizer):
|
|
| 79 |
return int(piece_id)
|
| 80 |
|
| 81 |
def _convert_id_to_token(self, index):
|
|
|
|
|
|
|
| 82 |
if index in self.added_tokens_decoder:
|
| 83 |
return self.added_tokens_decoder[index].content
|
| 84 |
return self.sp_model.id_to_piece(int(index))
|
|
|
|
| 43 |
str(token): int(token_id) for token, token_id in metadata.get("special_tokens", {}).items()
|
| 44 |
}
|
| 45 |
configured_special_tokens = [str(token) for token in metadata.get("configured_special_tokens", [])]
|
| 46 |
+
self.id_to_special_token = {
|
| 47 |
+
int(token_id): str(token) for token, token_id in self.special_token_ids.items()
|
| 48 |
+
}
|
| 49 |
|
| 50 |
merged_additional_tokens = list(additional_special_tokens or [])
|
| 51 |
for token in configured_special_tokens:
|
|
|
|
| 67 |
|
| 68 |
def get_vocab(self):
|
| 69 |
vocab = {self.sp_model.id_to_piece(i): i for i in range(self.vocab_size)}
|
| 70 |
+
vocab.update(self.special_token_ids)
|
| 71 |
vocab.update(self.added_tokens_encoder)
|
| 72 |
return vocab
|
| 73 |
|
|
|
|
| 83 |
return int(piece_id)
|
| 84 |
|
| 85 |
def _convert_id_to_token(self, index):
|
| 86 |
+
if index in self.id_to_special_token:
|
| 87 |
+
return self.id_to_special_token[index]
|
| 88 |
if index in self.added_tokens_decoder:
|
| 89 |
return self.added_tokens_decoder[index].content
|
| 90 |
return self.sp_model.id_to_piece(int(index))
|
tokenizer_config.json
CHANGED
|
@@ -1,90 +1,16 @@
|
|
| 1 |
{
|
| 2 |
-
"added_tokens_decoder": {
|
| 3 |
-
"4": {
|
| 4 |
-
"content": "\n",
|
| 5 |
-
"lstrip": false,
|
| 6 |
-
"normalized": false,
|
| 7 |
-
"rstrip": false,
|
| 8 |
-
"single_word": false,
|
| 9 |
-
"special": true
|
| 10 |
-
},
|
| 11 |
-
"5": {
|
| 12 |
-
"content": "<think>",
|
| 13 |
-
"lstrip": false,
|
| 14 |
-
"normalized": false,
|
| 15 |
-
"rstrip": false,
|
| 16 |
-
"single_word": false,
|
| 17 |
-
"special": true
|
| 18 |
-
},
|
| 19 |
-
"6": {
|
| 20 |
-
"content": "<user>",
|
| 21 |
-
"lstrip": false,
|
| 22 |
-
"normalized": false,
|
| 23 |
-
"rstrip": false,
|
| 24 |
-
"single_word": false,
|
| 25 |
-
"special": true
|
| 26 |
-
},
|
| 27 |
-
"7": {
|
| 28 |
-
"content": "<assistant>",
|
| 29 |
-
"lstrip": false,
|
| 30 |
-
"normalized": false,
|
| 31 |
-
"rstrip": false,
|
| 32 |
-
"single_word": false,
|
| 33 |
-
"special": true
|
| 34 |
-
},
|
| 35 |
-
"8": {
|
| 36 |
-
"content": "<image>",
|
| 37 |
-
"lstrip": false,
|
| 38 |
-
"normalized": false,
|
| 39 |
-
"rstrip": false,
|
| 40 |
-
"single_word": false,
|
| 41 |
-
"special": true
|
| 42 |
-
},
|
| 43 |
-
"8192": {
|
| 44 |
-
"content": "<BOS>",
|
| 45 |
-
"lstrip": false,
|
| 46 |
-
"normalized": false,
|
| 47 |
-
"rstrip": false,
|
| 48 |
-
"single_word": false,
|
| 49 |
-
"special": true
|
| 50 |
-
},
|
| 51 |
-
"8193": {
|
| 52 |
-
"content": "<EOS>",
|
| 53 |
-
"lstrip": false,
|
| 54 |
-
"normalized": false,
|
| 55 |
-
"rstrip": false,
|
| 56 |
-
"single_word": false,
|
| 57 |
-
"special": true
|
| 58 |
-
},
|
| 59 |
-
"8194": {
|
| 60 |
-
"content": "<UNK>",
|
| 61 |
-
"lstrip": false,
|
| 62 |
-
"normalized": false,
|
| 63 |
-
"rstrip": false,
|
| 64 |
-
"single_word": false,
|
| 65 |
-
"special": true
|
| 66 |
-
},
|
| 67 |
-
"8195": {
|
| 68 |
-
"content": "<PAD>",
|
| 69 |
-
"lstrip": false,
|
| 70 |
-
"normalized": false,
|
| 71 |
-
"rstrip": false,
|
| 72 |
-
"single_word": false,
|
| 73 |
-
"special": true
|
| 74 |
-
}
|
| 75 |
-
},
|
| 76 |
"backend": "custom",
|
| 77 |
"bos_token": "<BOS>",
|
| 78 |
"eos_token": "<EOS>",
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
"extra_special_tokens": [
|
| 80 |
"\n",
|
| 81 |
"<think>",
|
| 82 |
"<user>",
|
| 83 |
"<assistant>",
|
| 84 |
"<image>"
|
| 85 |
-
]
|
| 86 |
-
"model_max_length": 1000000000000000019884624838656,
|
| 87 |
-
"pad_token": "<PAD>",
|
| 88 |
-
"tokenizer_class": "TaoNetTokenizer",
|
| 89 |
-
"unk_token": "<UNK>"
|
| 90 |
}
|
|
|
|
| 1 |
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
"backend": "custom",
|
| 3 |
"bos_token": "<BOS>",
|
| 4 |
"eos_token": "<EOS>",
|
| 5 |
+
"unk_token": "<UNK>",
|
| 6 |
+
"pad_token": "<PAD>",
|
| 7 |
+
"tokenizer_class": "TaoNetTokenizer",
|
| 8 |
+
"model_max_length": 1000000000000000019884624838656,
|
| 9 |
"extra_special_tokens": [
|
| 10 |
"\n",
|
| 11 |
"<think>",
|
| 12 |
"<user>",
|
| 13 |
"<assistant>",
|
| 14 |
"<image>"
|
| 15 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|