Instructions to use Finisha-F-scratch/SoraForSLM-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Finisha-F-scratch/SoraForSLM-1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Finisha-F-scratch/SoraForSLM-1", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Finisha-F-scratch/SoraForSLM-1", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Finisha-F-scratch/SoraForSLM-1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Finisha-F-scratch/SoraForSLM-1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Finisha-F-scratch/SoraForSLM-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Finisha-F-scratch/SoraForSLM-1
- SGLang
How to use Finisha-F-scratch/SoraForSLM-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 "Finisha-F-scratch/SoraForSLM-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": "Finisha-F-scratch/SoraForSLM-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 "Finisha-F-scratch/SoraForSLM-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": "Finisha-F-scratch/SoraForSLM-1", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Finisha-F-scratch/SoraForSLM-1 with Docker Model Runner:
docker model run hf.co/Finisha-F-scratch/SoraForSLM-1
Update modeling_sora.py
Browse files- modeling_sora.py +15 -4
modeling_sora.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
from transformers import PreTrainedModel, GenerationMixin
|
|
|
|
| 4 |
from .configuration_sora import SoraConfig
|
| 5 |
|
| 6 |
class SoraForSLM(PreTrainedModel, GenerationMixin):
|
|
@@ -25,29 +26,39 @@ class SoraForSLM(PreTrainedModel, GenerationMixin):
|
|
| 25 |
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 26 |
self.post_init()
|
| 27 |
|
| 28 |
-
#
|
| 29 |
def get_input_embeddings(self):
|
| 30 |
return self.embeddings
|
| 31 |
|
| 32 |
-
# La méthode set_input_embeddings est requise par GenerationMixin
|
| 33 |
def set_input_embeddings(self, value):
|
| 34 |
self.embeddings = value
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
def forward(self, input_ids=None, labels=None, **kwargs):
|
| 37 |
seq_length = input_ids.size(1)
|
| 38 |
positions = torch.arange(seq_length, device=input_ids.device).unsqueeze(0)
|
| 39 |
|
|
|
|
| 40 |
x = self.embeddings(input_ids) + self.position_embeddings(positions)
|
| 41 |
|
|
|
|
| 42 |
for layer in self.layers:
|
| 43 |
x = layer(x)
|
| 44 |
|
| 45 |
logits = self.lm_head(x)
|
| 46 |
|
|
|
|
| 47 |
loss = None
|
| 48 |
if labels is not None:
|
| 49 |
loss_fct = nn.CrossEntropyLoss()
|
| 50 |
loss = loss_fct(logits.view(-1, self.config.vocab_size), labels.view(-1))
|
| 51 |
|
| 52 |
-
#
|
| 53 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
from transformers import PreTrainedModel, GenerationMixin
|
| 4 |
+
from transformers.modeling_outputs import CausalLMOutput
|
| 5 |
from .configuration_sora import SoraConfig
|
| 6 |
|
| 7 |
class SoraForSLM(PreTrainedModel, GenerationMixin):
|
|
|
|
| 26 |
self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)
|
| 27 |
self.post_init()
|
| 28 |
|
| 29 |
+
# Requis pour que GenerationMixin fonctionne
|
| 30 |
def get_input_embeddings(self):
|
| 31 |
return self.embeddings
|
| 32 |
|
|
|
|
| 33 |
def set_input_embeddings(self, value):
|
| 34 |
self.embeddings = value
|
| 35 |
|
| 36 |
+
def prepare_inputs_for_generation(self, input_ids, **kwargs):
|
| 37 |
+
# Nécessaire pour la génération en mode auto-régressif
|
| 38 |
+
return {"input_ids": input_ids}
|
| 39 |
+
|
| 40 |
def forward(self, input_ids=None, labels=None, **kwargs):
|
| 41 |
seq_length = input_ids.size(1)
|
| 42 |
positions = torch.arange(seq_length, device=input_ids.device).unsqueeze(0)
|
| 43 |
|
| 44 |
+
# Embedding + Position
|
| 45 |
x = self.embeddings(input_ids) + self.position_embeddings(positions)
|
| 46 |
|
| 47 |
+
# Passage dans les couches
|
| 48 |
for layer in self.layers:
|
| 49 |
x = layer(x)
|
| 50 |
|
| 51 |
logits = self.lm_head(x)
|
| 52 |
|
| 53 |
+
# Calcul de la perte si les labels sont fournis
|
| 54 |
loss = None
|
| 55 |
if labels is not None:
|
| 56 |
loss_fct = nn.CrossEntropyLoss()
|
| 57 |
loss = loss_fct(logits.view(-1, self.config.vocab_size), labels.view(-1))
|
| 58 |
|
| 59 |
+
#
|
| 60 |
+
# Retourner un objet CausalLMOutput au lieu d'un simple dictionnaire
|
| 61 |
+
return CausalLMOutput(
|
| 62 |
+
loss=loss,
|
| 63 |
+
logits=logits
|
| 64 |
+
)
|