Instructions to use MDaytek/chess-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use MDaytek/chess-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="MDaytek/chess-v1")# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("MDaytek/chess-v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use MDaytek/chess-v1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "MDaytek/chess-v1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "MDaytek/chess-v1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/MDaytek/chess-v1
- SGLang
How to use MDaytek/chess-v1 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 "MDaytek/chess-v1" \ --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": "MDaytek/chess-v1", "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 "MDaytek/chess-v1" \ --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": "MDaytek/chess-v1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use MDaytek/chess-v1 with Docker Model Runner:
docker model run hf.co/MDaytek/chess-v1
| import torch | |
| import torch.nn as nn | |
| from transformers import PreTrainedModel, PretrainedConfig | |
| class ChessConfig(PretrainedConfig): | |
| model_type = "chess_transformer" | |
| def __init__(self, vocab_size=1000, n_embd=128, n_layer=4, n_head=4, n_inner=512, n_ctx=256, **kwargs): | |
| super().__init__(**kwargs) | |
| self.vocab_size = vocab_size | |
| self.n_embd, self.n_layer, self.n_head, self.n_inner, self.n_ctx = n_embd, n_layer, n_head, n_inner, n_ctx | |
| class Block(nn.Module): | |
| def __init__(self, config): | |
| super().__init__() | |
| self.ln1=nn.LayerNorm(config.n_embd) | |
| self.attn=nn.MultiheadAttention(config.n_embd,config.n_head,batch_first=True) | |
| self.ln2=nn.LayerNorm(config.n_embd) | |
| self.mlp=nn.Sequential(nn.Linear(config.n_embd,config.n_inner),nn.GELU(),nn.Linear(config.n_inner, config.n_embd)) | |
| def forward(self, x, mask=None): | |
| attn_out,_=self.attn(self.ln1(x),self.ln1(x),self.ln1(x),attn_mask=mask,need_weights=False) | |
| return x+attn_out+self.mlp(self.ln2(x+attn_out)) | |
| class ChessForCausalLM(PreTrainedModel): | |
| config_class = ChessConfig | |
| def __init__(self, config): | |
| super().__init__(config) | |
| self.config = config | |
| self.token_emb = nn.Embedding(config.vocab_size, config.n_embd) | |
| self.pos_emb = nn.Embedding(config.n_ctx, config.n_embd) | |
| self.blocks = nn.ModuleList([Block(config) for _ in range(config.n_layer)]) | |
| self.ln_f = nn.LayerNorm(config.n_embd) | |
| self.lm_head = nn.Linear(config.n_embd, config.vocab_size, bias=False) | |
| self.apply(self._init_weights) | |
| def _init_weights(self, module): | |
| if isinstance(module, (nn.Linear, nn.Embedding)): torch.nn.init.normal_(module.weight, mean=0.0, std=0.02) | |
| def forward(self, input_ids, attention_mask=None, labels=None, **kwargs): | |
| B, T =input_ids.shape | |
| x = self.token_emb(input_ids)+self.pos_emb(torch.arange(T, device=input_ids.device)) | |
| mask = torch.triu(torch.ones(T, T, device=input_ids.device) * float('-inf'), diagonal=1) | |
| for block in self.blocks: x = block(x, mask=mask) | |
| logits = self.lm_head(self.ln_f(x)) | |
| loss = None | |
| if labels is not None: | |
| loss = nn.CrossEntropyLoss(ignore_index=-100)(logits[..., :-1, :].contiguous().view(-1, self.config.vocab_size), labels[..., 1:].contiguous().view(-1)) | |
| return {"loss": loss, "logits": logits} | |