Text Generation
Transformers
Safetensors
Russian
lingua_laboratorium_mechanicus
causal-lm
instruct
custom-architecture
warhammer-40k
russian
custom_code
Instructions to use GoldenGekko/LinguaLaboratoriumMechanicus-instruct with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use GoldenGekko/LinguaLaboratoriumMechanicus-instruct with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="GoldenGekko/LinguaLaboratoriumMechanicus-instruct", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("GoldenGekko/LinguaLaboratoriumMechanicus-instruct", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use GoldenGekko/LinguaLaboratoriumMechanicus-instruct with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "GoldenGekko/LinguaLaboratoriumMechanicus-instruct" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "GoldenGekko/LinguaLaboratoriumMechanicus-instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/GoldenGekko/LinguaLaboratoriumMechanicus-instruct
- SGLang
How to use GoldenGekko/LinguaLaboratoriumMechanicus-instruct 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 "GoldenGekko/LinguaLaboratoriumMechanicus-instruct" \ --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": "GoldenGekko/LinguaLaboratoriumMechanicus-instruct", "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 "GoldenGekko/LinguaLaboratoriumMechanicus-instruct" \ --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": "GoldenGekko/LinguaLaboratoriumMechanicus-instruct", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use GoldenGekko/LinguaLaboratoriumMechanicus-instruct with Docker Model Runner:
docker model run hf.co/GoldenGekko/LinguaLaboratoriumMechanicus-instruct
| from typing import Optional | |
| import torch | |
| import torch.nn as nn | |
| from transformers import GenerationMixin, PreTrainedModel | |
| from transformers.cache_utils import Cache | |
| from transformers.modeling_outputs import CausalLMOutputWithPast | |
| from .configuration_llm import LinguaLaboratoriumMechanicusConfig | |
| from llm.transformer import TransformerBlock | |
| class LLMForCausalLM(PreTrainedModel, GenerationMixin): | |
| config_class = LinguaLaboratoriumMechanicusConfig | |
| _no_split_modules = ['TransformerBlock'] | |
| def __init__(self, config: LinguaLaboratoriumMechanicusConfig): | |
| super().__init__(config) | |
| self.vocab_size = config.vocab_size | |
| self.emb_dim = config.emb_dim | |
| self.max_context_length = config.max_context_length | |
| self.token_emb = nn.Embedding(config.vocab_size, config.emb_dim) | |
| self.pos_emb = nn.Embedding(config.max_context_length, config.emb_dim) | |
| self.drop_emb = nn.Dropout(config.dropout) | |
| self.blocks = nn.Sequential(*[ | |
| TransformerBlock( | |
| emb_dim=config.emb_dim, | |
| n_heads=config.n_heads, | |
| context_length=config.max_context_length, | |
| dropout=config.dropout, | |
| qkv_bias=config.qkv_bias, | |
| ) | |
| for _ in range(config.n_layers) | |
| ]) | |
| self.final_norm = nn.LayerNorm(config.emb_dim) | |
| self.out_head = nn.Linear(config.emb_dim, config.vocab_size, bias=False) | |
| self.post_init() | |
| def _init_weights(module): | |
| if isinstance(module, (nn.Linear, nn.Embedding)): | |
| torch.nn.init.normal_(module.weight, mean=0.0, std=0.02) | |
| if isinstance(module, nn.Linear) and module.bias is not None: | |
| torch.nn.init.zeros_(module.bias) | |
| def forward( | |
| self, | |
| input_ids: torch.LongTensor | None = None, | |
| attention_mask: torch.Tensor | None = None, | |
| past_key_values: Cache | None = None, | |
| use_cache: bool | None = None, | |
| **kwargs, | |
| ) -> CausalLMOutputWithPast: | |
| if input_ids is None: | |
| raise ValueError('input_ids обязателен') | |
| _, n_tokens = input_ids.size() | |
| if n_tokens > self.max_context_length: | |
| raise ValueError( | |
| f'Длина входной последовательности ({n_tokens}) превышает ' | |
| f'максимальную заданную ({self.max_context_length}).' | |
| ) | |
| x = self.drop_emb( | |
| self.token_emb(input_ids) + | |
| self.pos_emb( | |
| torch.arange(n_tokens, device=input_ids.device).unsqueeze(0) | |
| ) | |
| ) | |
| x = self.blocks(x) | |
| logits = self.out_head(self.final_norm(x)) | |
| return CausalLMOutputWithPast(logits=logits, past_key_values=None) | |
| def prepare_inputs_for_generation(self, input_ids, **kwargs): | |
| return {'input_ids': input_ids} | |