Text Generation
Transformers
Safetensors
pinyin_code
causal-lm
trust-remote-code
sentencepiece
custom_code
Instructions to use timorobrecht/full_chinese_gpu3.2-dpo with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use timorobrecht/full_chinese_gpu3.2-dpo with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="timorobrecht/full_chinese_gpu3.2-dpo", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("timorobrecht/full_chinese_gpu3.2-dpo", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use timorobrecht/full_chinese_gpu3.2-dpo 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.2-dpo" # 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.2-dpo", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/timorobrecht/full_chinese_gpu3.2-dpo
- SGLang
How to use timorobrecht/full_chinese_gpu3.2-dpo 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.2-dpo" \ --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.2-dpo", "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.2-dpo" \ --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.2-dpo", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use timorobrecht/full_chinese_gpu3.2-dpo with Docker Model Runner:
docker model run hf.co/timorobrecht/full_chinese_gpu3.2-dpo
File size: 3,051 Bytes
eea02cb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 | """Configuration for the Transformers-compatible pinyin-code causal LM."""
from __future__ import annotations
import functools
import os
import pathlib
from transformers import PretrainedConfig
_UTF8_PATH_OPEN_PATCH_MARKER = "_pinyin_code_utf8_path_open_patch"
def install_utf8_path_open_patch() -> None:
"""Default text-mode ``Path.open`` calls to UTF-8 when encoding is omitted.
Some external Windows evaluation pipelines call ``Path.open("r")`` on
UTF-8 JSONL data before specifying an encoding. The model is loaded before
those datasets, so this narrow compatibility shim lets such pipelines read
Mandarin evaluation files without repository-side changes. Explicit
encodings and binary modes are left untouched.
"""
current_open = pathlib.Path.open
if getattr(current_open, _UTF8_PATH_OPEN_PATCH_MARKER, False):
return
@functools.wraps(current_open)
def utf8_default_open(
self,
mode: str = "r",
buffering: int = -1,
encoding: str | None = None,
errors: str | None = None,
newline: str | None = None,
):
if encoding is None and "b" not in mode:
encoding = "utf-8"
return current_open(
self,
mode=mode,
buffering=buffering,
encoding=encoding,
errors=errors,
newline=newline,
)
setattr(utf8_default_open, _UTF8_PATH_OPEN_PATCH_MARKER, True)
pathlib.Path.open = utf8_default_open
class PinyinCodeConfig(PretrainedConfig):
"""Configuration for the compact GPT-style pinyin-code decoder."""
model_type = "pinyin_code"
def __init__(
self,
vocab_size: int = 8000,
block_size: int = 128,
n_layer: int = 6,
n_head: int = 8,
n_embd: int = 256,
dropout: float = 0.1,
bos_token_id: int | None = None,
eos_token_id: int | None = None,
pad_token_id: int | None = None,
unk_token_id: int | None = None,
patch_pathlib_utf8_open: bool = False,
**kwargs,
) -> None:
super().__init__(
bos_token_id=bos_token_id,
eos_token_id=eos_token_id,
pad_token_id=pad_token_id,
unk_token_id=unk_token_id,
**kwargs,
)
self.vocab_size = vocab_size
self.block_size = block_size
self.n_layer = n_layer
self.n_head = n_head
self.n_embd = n_embd
self.dropout = dropout
self.num_hidden_layers = n_layer
self.num_attention_heads = n_head
self.hidden_size = n_embd
self.max_position_embeddings = block_size
self.is_decoder = True
self.is_encoder_decoder = False
self.use_cache = False
self.patch_pathlib_utf8_open = patch_pathlib_utf8_open
if (
patch_pathlib_utf8_open
and os.environ.get("PINYIN_CODE_DISABLE_UTF8_OPEN_PATCH") != "1"
):
install_utf8_path_open_patch()
|