Text Generation
Transformers
Safetensors
pinyin_code
causal-lm
trust-remote-code
sentencepiece
custom_code
Instructions to use timorobrecht/full_chinese_gpu3.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use timorobrecht/full_chinese_gpu3.1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="timorobrecht/full_chinese_gpu3.1", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("timorobrecht/full_chinese_gpu3.1", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use timorobrecht/full_chinese_gpu3.1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "timorobrecht/full_chinese_gpu3.1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "timorobrecht/full_chinese_gpu3.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/timorobrecht/full_chinese_gpu3.1
- SGLang
How to use timorobrecht/full_chinese_gpu3.1 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 "timorobrecht/full_chinese_gpu3.1" \ --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": "timorobrecht/full_chinese_gpu3.1", "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 "timorobrecht/full_chinese_gpu3.1" \ --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": "timorobrecht/full_chinese_gpu3.1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use timorobrecht/full_chinese_gpu3.1 with Docker Model Runner:
docker model run hf.co/timorobrecht/full_chinese_gpu3.1
Upload folder using huggingface_hub
Browse files- README.md +7 -0
- config.json +3 -2
- configuration_pinyin_code.py +72 -21
- hf/configuration_pinyin_code.py +72 -21
README.md
CHANGED
|
@@ -50,6 +50,13 @@ The tokenizer accepts raw text through standard calls such as
|
|
| 50 |
`tokenizer(text)`, `tokenizer(text, add_special_tokens=False)`, and
|
| 51 |
`tokenizer(texts, padding=True, truncation=True, return_tensors="pt")`.
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
Export metadata:
|
| 54 |
|
| 55 |
- transliteration: `pinyin-code`
|
|
|
|
| 50 |
`tokenizer(text)`, `tokenizer(text, add_special_tokens=False)`, and
|
| 51 |
`tokenizer(texts, padding=True, truncation=True, return_tensors="pt")`.
|
| 52 |
|
| 53 |
+
This export sets `patch_pathlib_utf8_open=true` in `config.json`. When loaded
|
| 54 |
+
with `trust_remote_code=True`, the config installs a narrow Windows
|
| 55 |
+
compatibility shim so later text-mode `Path.open("r")` calls without an
|
| 56 |
+
explicit encoding default to UTF-8. Set
|
| 57 |
+
`PINYIN_CODE_DISABLE_UTF8_OPEN_PATCH=1` before loading the model to disable
|
| 58 |
+
that shim.
|
| 59 |
+
|
| 60 |
Export metadata:
|
| 61 |
|
| 62 |
- transliteration: `pinyin-code`
|
config.json
CHANGED
|
@@ -26,8 +26,9 @@
|
|
| 26 |
"n_layer": 8,
|
| 27 |
"num_attention_heads": 8,
|
| 28 |
"num_hidden_layers": 8,
|
| 29 |
-
"pad_token_id": 0,
|
| 30 |
-
"
|
|
|
|
| 31 |
"unk_token_id": 1,
|
| 32 |
"use_cache": false,
|
| 33 |
"vocab_size": 16000
|
|
|
|
| 26 |
"n_layer": 8,
|
| 27 |
"num_attention_heads": 8,
|
| 28 |
"num_hidden_layers": 8,
|
| 29 |
+
"pad_token_id": 0,
|
| 30 |
+
"patch_pathlib_utf8_open": true,
|
| 31 |
+
"transformers_version": "5.10.2",
|
| 32 |
"unk_token_id": 1,
|
| 33 |
"use_cache": false,
|
| 34 |
"vocab_size": 16000
|
configuration_pinyin_code.py
CHANGED
|
@@ -1,12 +1,56 @@
|
|
| 1 |
-
"""Configuration for the Transformers-compatible pinyin-code causal LM."""
|
| 2 |
-
|
| 3 |
-
from __future__ import annotations
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
model_type = "pinyin_code"
|
| 12 |
|
|
@@ -19,14 +63,15 @@ class PinyinCodeConfig(PretrainedConfig):
|
|
| 19 |
n_embd: int = 256,
|
| 20 |
dropout: float = 0.1,
|
| 21 |
bos_token_id: int | None = None,
|
| 22 |
-
eos_token_id: int | None = None,
|
| 23 |
-
pad_token_id: int | None = None,
|
| 24 |
-
unk_token_id: int | None = None,
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
pad_token_id=pad_token_id,
|
| 31 |
unk_token_id=unk_token_id,
|
| 32 |
**kwargs,
|
|
@@ -40,7 +85,13 @@ class PinyinCodeConfig(PretrainedConfig):
|
|
| 40 |
self.num_hidden_layers = n_layer
|
| 41 |
self.num_attention_heads = n_head
|
| 42 |
self.hidden_size = n_embd
|
| 43 |
-
self.max_position_embeddings = block_size
|
| 44 |
-
self.is_decoder = True
|
| 45 |
-
self.is_encoder_decoder = False
|
| 46 |
-
self.use_cache = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Configuration for the Transformers-compatible pinyin-code causal LM."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import functools
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
|
| 9 |
+
from transformers import PretrainedConfig
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
_UTF8_PATH_OPEN_PATCH_MARKER = "_pinyin_code_utf8_path_open_patch"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def install_utf8_path_open_patch() -> None:
|
| 16 |
+
"""Default text-mode ``Path.open`` calls to UTF-8 when encoding is omitted.
|
| 17 |
+
|
| 18 |
+
Some external Windows evaluation pipelines call ``Path.open("r")`` on
|
| 19 |
+
UTF-8 JSONL data before specifying an encoding. The model is loaded before
|
| 20 |
+
those datasets, so this narrow compatibility shim lets such pipelines read
|
| 21 |
+
Mandarin evaluation files without repository-side changes. Explicit
|
| 22 |
+
encodings and binary modes are left untouched.
|
| 23 |
+
"""
|
| 24 |
+
current_open = pathlib.Path.open
|
| 25 |
+
if getattr(current_open, _UTF8_PATH_OPEN_PATCH_MARKER, False):
|
| 26 |
+
return
|
| 27 |
+
|
| 28 |
+
@functools.wraps(current_open)
|
| 29 |
+
def utf8_default_open(
|
| 30 |
+
self,
|
| 31 |
+
mode: str = "r",
|
| 32 |
+
buffering: int = -1,
|
| 33 |
+
encoding: str | None = None,
|
| 34 |
+
errors: str | None = None,
|
| 35 |
+
newline: str | None = None,
|
| 36 |
+
):
|
| 37 |
+
if encoding is None and "b" not in mode:
|
| 38 |
+
encoding = "utf-8"
|
| 39 |
+
return current_open(
|
| 40 |
+
self,
|
| 41 |
+
mode=mode,
|
| 42 |
+
buffering=buffering,
|
| 43 |
+
encoding=encoding,
|
| 44 |
+
errors=errors,
|
| 45 |
+
newline=newline,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
setattr(utf8_default_open, _UTF8_PATH_OPEN_PATCH_MARKER, True)
|
| 49 |
+
pathlib.Path.open = utf8_default_open
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class PinyinCodeConfig(PretrainedConfig):
|
| 53 |
+
"""Configuration for the compact GPT-style pinyin-code decoder."""
|
| 54 |
|
| 55 |
model_type = "pinyin_code"
|
| 56 |
|
|
|
|
| 63 |
n_embd: int = 256,
|
| 64 |
dropout: float = 0.1,
|
| 65 |
bos_token_id: int | None = None,
|
| 66 |
+
eos_token_id: int | None = None,
|
| 67 |
+
pad_token_id: int | None = None,
|
| 68 |
+
unk_token_id: int | None = None,
|
| 69 |
+
patch_pathlib_utf8_open: bool = False,
|
| 70 |
+
**kwargs,
|
| 71 |
+
) -> None:
|
| 72 |
+
super().__init__(
|
| 73 |
+
bos_token_id=bos_token_id,
|
| 74 |
+
eos_token_id=eos_token_id,
|
| 75 |
pad_token_id=pad_token_id,
|
| 76 |
unk_token_id=unk_token_id,
|
| 77 |
**kwargs,
|
|
|
|
| 85 |
self.num_hidden_layers = n_layer
|
| 86 |
self.num_attention_heads = n_head
|
| 87 |
self.hidden_size = n_embd
|
| 88 |
+
self.max_position_embeddings = block_size
|
| 89 |
+
self.is_decoder = True
|
| 90 |
+
self.is_encoder_decoder = False
|
| 91 |
+
self.use_cache = False
|
| 92 |
+
self.patch_pathlib_utf8_open = patch_pathlib_utf8_open
|
| 93 |
+
if (
|
| 94 |
+
patch_pathlib_utf8_open
|
| 95 |
+
and os.environ.get("PINYIN_CODE_DISABLE_UTF8_OPEN_PATCH") != "1"
|
| 96 |
+
):
|
| 97 |
+
install_utf8_path_open_patch()
|
hf/configuration_pinyin_code.py
CHANGED
|
@@ -1,12 +1,56 @@
|
|
| 1 |
-
"""Configuration for the Transformers-compatible pinyin-code causal LM."""
|
| 2 |
-
|
| 3 |
-
from __future__ import annotations
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
model_type = "pinyin_code"
|
| 12 |
|
|
@@ -19,14 +63,15 @@ class PinyinCodeConfig(PretrainedConfig):
|
|
| 19 |
n_embd: int = 256,
|
| 20 |
dropout: float = 0.1,
|
| 21 |
bos_token_id: int | None = None,
|
| 22 |
-
eos_token_id: int | None = None,
|
| 23 |
-
pad_token_id: int | None = None,
|
| 24 |
-
unk_token_id: int | None = None,
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
| 30 |
pad_token_id=pad_token_id,
|
| 31 |
unk_token_id=unk_token_id,
|
| 32 |
**kwargs,
|
|
@@ -40,7 +85,13 @@ class PinyinCodeConfig(PretrainedConfig):
|
|
| 40 |
self.num_hidden_layers = n_layer
|
| 41 |
self.num_attention_heads = n_head
|
| 42 |
self.hidden_size = n_embd
|
| 43 |
-
self.max_position_embeddings = block_size
|
| 44 |
-
self.is_decoder = True
|
| 45 |
-
self.is_encoder_decoder = False
|
| 46 |
-
self.use_cache = False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Configuration for the Transformers-compatible pinyin-code causal LM."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import functools
|
| 6 |
+
import os
|
| 7 |
+
import pathlib
|
| 8 |
+
|
| 9 |
+
from transformers import PretrainedConfig
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
_UTF8_PATH_OPEN_PATCH_MARKER = "_pinyin_code_utf8_path_open_patch"
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def install_utf8_path_open_patch() -> None:
|
| 16 |
+
"""Default text-mode ``Path.open`` calls to UTF-8 when encoding is omitted.
|
| 17 |
+
|
| 18 |
+
Some external Windows evaluation pipelines call ``Path.open("r")`` on
|
| 19 |
+
UTF-8 JSONL data before specifying an encoding. The model is loaded before
|
| 20 |
+
those datasets, so this narrow compatibility shim lets such pipelines read
|
| 21 |
+
Mandarin evaluation files without repository-side changes. Explicit
|
| 22 |
+
encodings and binary modes are left untouched.
|
| 23 |
+
"""
|
| 24 |
+
current_open = pathlib.Path.open
|
| 25 |
+
if getattr(current_open, _UTF8_PATH_OPEN_PATCH_MARKER, False):
|
| 26 |
+
return
|
| 27 |
+
|
| 28 |
+
@functools.wraps(current_open)
|
| 29 |
+
def utf8_default_open(
|
| 30 |
+
self,
|
| 31 |
+
mode: str = "r",
|
| 32 |
+
buffering: int = -1,
|
| 33 |
+
encoding: str | None = None,
|
| 34 |
+
errors: str | None = None,
|
| 35 |
+
newline: str | None = None,
|
| 36 |
+
):
|
| 37 |
+
if encoding is None and "b" not in mode:
|
| 38 |
+
encoding = "utf-8"
|
| 39 |
+
return current_open(
|
| 40 |
+
self,
|
| 41 |
+
mode=mode,
|
| 42 |
+
buffering=buffering,
|
| 43 |
+
encoding=encoding,
|
| 44 |
+
errors=errors,
|
| 45 |
+
newline=newline,
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
setattr(utf8_default_open, _UTF8_PATH_OPEN_PATCH_MARKER, True)
|
| 49 |
+
pathlib.Path.open = utf8_default_open
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
class PinyinCodeConfig(PretrainedConfig):
|
| 53 |
+
"""Configuration for the compact GPT-style pinyin-code decoder."""
|
| 54 |
|
| 55 |
model_type = "pinyin_code"
|
| 56 |
|
|
|
|
| 63 |
n_embd: int = 256,
|
| 64 |
dropout: float = 0.1,
|
| 65 |
bos_token_id: int | None = None,
|
| 66 |
+
eos_token_id: int | None = None,
|
| 67 |
+
pad_token_id: int | None = None,
|
| 68 |
+
unk_token_id: int | None = None,
|
| 69 |
+
patch_pathlib_utf8_open: bool = False,
|
| 70 |
+
**kwargs,
|
| 71 |
+
) -> None:
|
| 72 |
+
super().__init__(
|
| 73 |
+
bos_token_id=bos_token_id,
|
| 74 |
+
eos_token_id=eos_token_id,
|
| 75 |
pad_token_id=pad_token_id,
|
| 76 |
unk_token_id=unk_token_id,
|
| 77 |
**kwargs,
|
|
|
|
| 85 |
self.num_hidden_layers = n_layer
|
| 86 |
self.num_attention_heads = n_head
|
| 87 |
self.hidden_size = n_embd
|
| 88 |
+
self.max_position_embeddings = block_size
|
| 89 |
+
self.is_decoder = True
|
| 90 |
+
self.is_encoder_decoder = False
|
| 91 |
+
self.use_cache = False
|
| 92 |
+
self.patch_pathlib_utf8_open = patch_pathlib_utf8_open
|
| 93 |
+
if (
|
| 94 |
+
patch_pathlib_utf8_open
|
| 95 |
+
and os.environ.get("PINYIN_CODE_DISABLE_UTF8_OPEN_PATCH") != "1"
|
| 96 |
+
):
|
| 97 |
+
install_utf8_path_open_patch()
|