Instructions to use Xuezha/RecombinationTransformer-base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Xuezha/RecombinationTransformer-base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Xuezha/RecombinationTransformer-base", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Xuezha/RecombinationTransformer-base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Xuezha/RecombinationTransformer-base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Xuezha/RecombinationTransformer-base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Xuezha/RecombinationTransformer-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Xuezha/RecombinationTransformer-base
- SGLang
How to use Xuezha/RecombinationTransformer-base 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 "Xuezha/RecombinationTransformer-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Xuezha/RecombinationTransformer-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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 "Xuezha/RecombinationTransformer-base" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Xuezha/RecombinationTransformer-base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Xuezha/RecombinationTransformer-base with Docker Model Runner:
docker model run hf.co/Xuezha/RecombinationTransformer-base
Update modeling.py
Browse files- modeling.py +2 -15
modeling.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
from transformers import PreTrainedModel
|
|
|
|
| 4 |
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 5 |
|
| 6 |
from .configure import RecombinationTransformerConfig
|
|
@@ -172,26 +173,12 @@ class RecombinationTransformerForCausalLM(PreTrainedModel):
|
|
| 172 |
|
| 173 |
return CausalLMOutputWithPast(logits=logits, past_key_values=past_key_values)
|
| 174 |
|
| 175 |
-
@classmethod
|
| 176 |
-
def from_pretrained(cls, *args, **kwargs):
|
| 177 |
-
config = kwargs.pop('config', None)
|
| 178 |
-
if config is None:
|
| 179 |
-
config = CustomTransformerConfig.from_pretrained(*args, **kwargs)
|
| 180 |
-
model = cls(config)
|
| 181 |
-
state_dict = torch.load(kwargs['pretrained_model_name_or_path'], map_location='cpu')
|
| 182 |
-
model.load_state_dict(state_dict)
|
| 183 |
-
return model
|
| 184 |
-
|
| 185 |
-
def save_pretrained(self, save_directory):
|
| 186 |
-
torch.save(self.state_dict(), f"{save_directory}/pytorch_model.bin")
|
| 187 |
-
self.config.save_pretrained(save_directory)
|
| 188 |
-
|
| 189 |
def generate(self, input_ids, max_length=20, min_length=None, num_return_sequences=1):
|
| 190 |
logits_processor = LogitsProcessorList()
|
| 191 |
stopping_criteria = StoppingCriteriaList([MaxLengthCriteria(max_length=max_length)])
|
| 192 |
|
| 193 |
if min_length is not None:
|
| 194 |
-
logits_processor.append(MinLengthLogitsProcessor(min_length, eos_token_id=
|
| 195 |
|
| 196 |
outputs = super().generate(
|
| 197 |
input_ids=input_ids,
|
|
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
from transformers import PreTrainedModel
|
| 4 |
+
from transformers import LogitsProcessorList, StoppingCriteriaList, MaxLengthCriteria, MinLengthLogitsProcessor
|
| 5 |
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 6 |
|
| 7 |
from .configure import RecombinationTransformerConfig
|
|
|
|
| 173 |
|
| 174 |
return CausalLMOutputWithPast(logits=logits, past_key_values=past_key_values)
|
| 175 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
def generate(self, input_ids, max_length=20, min_length=None, num_return_sequences=1):
|
| 177 |
logits_processor = LogitsProcessorList()
|
| 178 |
stopping_criteria = StoppingCriteriaList([MaxLengthCriteria(max_length=max_length)])
|
| 179 |
|
| 180 |
if min_length is not None:
|
| 181 |
+
logits_processor.append(MinLengthLogitsProcessor(min_length, eos_token_id=config.eos_token_id))
|
| 182 |
|
| 183 |
outputs = super().generate(
|
| 184 |
input_ids=input_ids,
|