Text Generation
Transformers
Safetensors
English
suprabrain
gated-deltanet
linear-attention
sliding-window-attention
custom-architecture
custom_code
Instructions to use SupraLabs/SupraBrain-50M with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SupraLabs/SupraBrain-50M with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="SupraLabs/SupraBrain-50M", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("SupraLabs/SupraBrain-50M", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use SupraLabs/SupraBrain-50M with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "SupraLabs/SupraBrain-50M" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "SupraLabs/SupraBrain-50M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/SupraLabs/SupraBrain-50M
- SGLang
How to use SupraLabs/SupraBrain-50M 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 "SupraLabs/SupraBrain-50M" \ --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": "SupraLabs/SupraBrain-50M", "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 "SupraLabs/SupraBrain-50M" \ --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": "SupraLabs/SupraBrain-50M", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use SupraLabs/SupraBrain-50M with Docker Model Runner:
docker model run hf.co/SupraLabs/SupraBrain-50M
Update modeling_suprabrain.py
Browse files- modeling_suprabrain.py +15 -1
modeling_suprabrain.py
CHANGED
|
@@ -22,6 +22,7 @@ from torch.utils.data import Dataset, SequentialSampler
|
|
| 22 |
|
| 23 |
from transformers import PretrainedConfig, PreTrainedModel
|
| 24 |
from transformers.modeling_outputs import CausalLMOutputWithPast
|
|
|
|
| 25 |
|
| 26 |
# ---------------------------------------------------------------------------
|
| 27 |
# Optional backends
|
|
@@ -532,7 +533,7 @@ def _ce_chunk(h, W, labels, z_coef, softcap):
|
|
| 532 |
return loss
|
| 533 |
|
| 534 |
|
| 535 |
-
class SupraBrainForCausalLM(SupraBrainPreTrainedModel):
|
| 536 |
_tied_weights_keys = {}
|
| 537 |
|
| 538 |
def __init__(self, cfg: SupraBrainConfig):
|
|
@@ -543,6 +544,9 @@ class SupraBrainForCausalLM(SupraBrainPreTrainedModel):
|
|
| 543 |
self.ub_a = nn.Parameter(torch.zeros(cfg.hidden_size, r))
|
| 544 |
self.ub_b = nn.Parameter(torch.zeros(cfg.hidden_size, r))
|
| 545 |
nn.init.normal_(self.ub_a, 0.0, cfg.initializer_range)
|
|
|
|
|
|
|
|
|
|
| 546 |
self.post_init()
|
| 547 |
|
| 548 |
def get_input_embeddings(self):
|
|
@@ -585,6 +589,16 @@ class SupraBrainForCausalLM(SupraBrainPreTrainedModel):
|
|
| 585 |
use_reentrant=False)
|
| 586 |
return CausalLMOutputWithPast(loss=tot / ls.numel(), logits=None)
|
| 587 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 588 |
|
| 589 |
# ---- HF Auto-Registration -------------------------------------------------
|
| 590 |
def register_hf():
|
|
|
|
| 22 |
|
| 23 |
from transformers import PretrainedConfig, PreTrainedModel
|
| 24 |
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 25 |
+
from transformers import GenerationMixin
|
| 26 |
|
| 27 |
# ---------------------------------------------------------------------------
|
| 28 |
# Optional backends
|
|
|
|
| 533 |
return loss
|
| 534 |
|
| 535 |
|
| 536 |
+
class SupraBrainForCausalLM(SupraBrainPreTrainedModel, GenerationMixin):
|
| 537 |
_tied_weights_keys = {}
|
| 538 |
|
| 539 |
def __init__(self, cfg: SupraBrainConfig):
|
|
|
|
| 544 |
self.ub_a = nn.Parameter(torch.zeros(cfg.hidden_size, r))
|
| 545 |
self.ub_b = nn.Parameter(torch.zeros(cfg.hidden_size, r))
|
| 546 |
nn.init.normal_(self.ub_a, 0.0, cfg.initializer_range)
|
| 547 |
+
|
| 548 |
+
# GenerationMixin requires main_input_name to be specified
|
| 549 |
+
self.main_input_name = "input_ids"
|
| 550 |
self.post_init()
|
| 551 |
|
| 552 |
def get_input_embeddings(self):
|
|
|
|
| 589 |
use_reentrant=False)
|
| 590 |
return CausalLMOutputWithPast(loss=tot / ls.numel(), logits=None)
|
| 591 |
|
| 592 |
+
def prepare_inputs_for_generation(
|
| 593 |
+
self, input_ids, past_key_values=None, attention_mask=None, **kwargs
|
| 594 |
+
):
|
| 595 |
+
return {
|
| 596 |
+
"input_ids": input_ids,
|
| 597 |
+
"past_key_values": past_key_values,
|
| 598 |
+
"use_cache": kwargs.get("use_cache", False),
|
| 599 |
+
"attention_mask": attention_mask,
|
| 600 |
+
}
|
| 601 |
+
|
| 602 |
|
| 603 |
# ---- HF Auto-Registration -------------------------------------------------
|
| 604 |
def register_hf():
|