Instructions to use ssslakter/LLaDA-8B-Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use ssslakter/LLaDA-8B-Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="ssslakter/LLaDA-8B-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("ssslakter/LLaDA-8B-Base", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use ssslakter/LLaDA-8B-Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "ssslakter/LLaDA-8B-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": "ssslakter/LLaDA-8B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/ssslakter/LLaDA-8B-Base
- SGLang
How to use ssslakter/LLaDA-8B-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 "ssslakter/LLaDA-8B-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": "ssslakter/LLaDA-8B-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 "ssslakter/LLaDA-8B-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": "ssslakter/LLaDA-8B-Base", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use ssslakter/LLaDA-8B-Base with Docker Model Runner:
docker model run hf.co/ssslakter/LLaDA-8B-Base
Slava Chaunin commited on
Commit ·
ca08856
1
Parent(s): 05f5a83
update to transformers 5 format
Browse files- configuration_llada.py +3 -0
- modeling_llada.py +7 -13
configuration_llada.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
LLaDA configuration
|
| 3 |
"""
|
| 4 |
from transformers import AutoConfig, PretrainedConfig
|
|
|
|
| 5 |
|
| 6 |
from enum import Enum
|
| 7 |
from os import PathLike
|
|
@@ -430,9 +431,11 @@ class ActivationCheckpointingStrategy(StrEnum):
|
|
| 430 |
"""
|
| 431 |
|
| 432 |
|
|
|
|
| 433 |
class LLaDAConfig(PretrainedConfig):
|
| 434 |
model_type = "llada"
|
| 435 |
keys_to_ignore_at_inference = ["past_key_values"] # TODO: confirm
|
|
|
|
| 436 |
|
| 437 |
def __init__(self, use_cache: bool = False, **kwargs):
|
| 438 |
model_config = ModelConfig()
|
|
|
|
| 2 |
LLaDA configuration
|
| 3 |
"""
|
| 4 |
from transformers import AutoConfig, PretrainedConfig
|
| 5 |
+
from huggingface_hub.dataclasses import strict
|
| 6 |
|
| 7 |
from enum import Enum
|
| 8 |
from os import PathLike
|
|
|
|
| 431 |
"""
|
| 432 |
|
| 433 |
|
| 434 |
+
@strict
|
| 435 |
class LLaDAConfig(PretrainedConfig):
|
| 436 |
model_type = "llada"
|
| 437 |
keys_to_ignore_at_inference = ["past_key_values"] # TODO: confirm
|
| 438 |
+
tie_word_embeddings: bool = False
|
| 439 |
|
| 440 |
def __init__(self, use_cache: bool = False, **kwargs):
|
| 441 |
model_config = ModelConfig()
|
modeling_llada.py
CHANGED
|
@@ -27,6 +27,7 @@ import torch.nn as nn
|
|
| 27 |
import torch.nn.functional as F
|
| 28 |
from torch import einsum
|
| 29 |
from transformers import PreTrainedModel
|
|
|
|
| 30 |
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 31 |
from transformers.models.auto import AutoModel
|
| 32 |
from transformers.cache_utils import Cache
|
|
@@ -1393,6 +1394,7 @@ class LLaDAModelLM(PreTrainedModel):
|
|
| 1393 |
config_class = LLaDAConfig
|
| 1394 |
base_model_prefix = "model"
|
| 1395 |
_no_split_modules = ["LLaDABlock", "LLaDASequentialBlock", "LLaDALlamaBlock"]
|
|
|
|
| 1396 |
|
| 1397 |
def __init__(self, config: LLaDAConfig, model: Optional[LLaDAModel] = None, init_params: bool = False):
|
| 1398 |
super().__init__(config)
|
|
@@ -1404,10 +1406,12 @@ class LLaDAModelLM(PreTrainedModel):
|
|
| 1404 |
self.model = LLaDAModel(model_config, init_params=init_params)
|
| 1405 |
else:
|
| 1406 |
self.model = model
|
|
|
|
| 1407 |
|
|
|
|
| 1408 |
def forward(
|
| 1409 |
self,
|
| 1410 |
-
input_ids: torch.LongTensor = None,
|
| 1411 |
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1412 |
attention_mask: Optional[torch.Tensor] = None,
|
| 1413 |
attention_bias: Optional[torch.Tensor] = None,
|
|
@@ -1416,8 +1420,7 @@ class LLaDAModelLM(PreTrainedModel):
|
|
| 1416 |
use_cache: Optional[bool] = None,
|
| 1417 |
output_attentions: Optional[bool] = None,
|
| 1418 |
output_hidden_states: Optional[bool] = None,
|
| 1419 |
-
|
| 1420 |
-
cache_position: Optional[Cache] = None, # This is a hack mitigation of an issue in transformers `4.39.x`
|
| 1421 |
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 1422 |
if use_cache is None:
|
| 1423 |
use_cache = self.config.use_cache
|
|
@@ -1425,7 +1428,6 @@ class LLaDAModelLM(PreTrainedModel):
|
|
| 1425 |
if output_attentions:
|
| 1426 |
raise ValueError("output_attentions is not yet supported in LLaDA")
|
| 1427 |
|
| 1428 |
-
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 1429 |
|
| 1430 |
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 1431 |
outputs = self.model.forward(
|
|
@@ -1441,14 +1443,10 @@ class LLaDAModelLM(PreTrainedModel):
|
|
| 1441 |
logits = outputs.logits
|
| 1442 |
hidden_states = outputs.hidden_states
|
| 1443 |
|
| 1444 |
-
loss = None
|
| 1445 |
if labels is not None:
|
| 1446 |
import warnings
|
| 1447 |
warnings.warn("Note that for LLaDA, you cannot calculate the loss here.", UserWarning)
|
| 1448 |
-
|
| 1449 |
-
output = (logits,) + outputs[1:]
|
| 1450 |
-
return (loss,) + output if loss is not None else output
|
| 1451 |
-
|
| 1452 |
return CausalLMOutputWithPast(
|
| 1453 |
logits=logits,
|
| 1454 |
past_key_values=outputs.attn_key_values,
|
|
@@ -1498,9 +1496,5 @@ class LLaDAModelLM(PreTrainedModel):
|
|
| 1498 |
else:
|
| 1499 |
self.model.transformer.ff_out = value
|
| 1500 |
|
| 1501 |
-
def tie_weights(self):
|
| 1502 |
-
if self.config.weight_tying:
|
| 1503 |
-
self.model.transformer.ff_out = self.model.transformer.wte
|
| 1504 |
-
|
| 1505 |
# Register the model so that it is available for transformer pipelines, auto-loading, etc.
|
| 1506 |
AutoModel.register(LLaDAConfig, LLaDAModelLM)
|
|
|
|
| 27 |
import torch.nn.functional as F
|
| 28 |
from torch import einsum
|
| 29 |
from transformers import PreTrainedModel
|
| 30 |
+
from transformers.utils import can_return_tuple
|
| 31 |
from transformers.modeling_outputs import CausalLMOutputWithPast
|
| 32 |
from transformers.models.auto import AutoModel
|
| 33 |
from transformers.cache_utils import Cache
|
|
|
|
| 1394 |
config_class = LLaDAConfig
|
| 1395 |
base_model_prefix = "model"
|
| 1396 |
_no_split_modules = ["LLaDABlock", "LLaDASequentialBlock", "LLaDALlamaBlock"]
|
| 1397 |
+
_tied_weights_keys = {"model.transformer.ff_out.weight": "model.transformer.wte"}
|
| 1398 |
|
| 1399 |
def __init__(self, config: LLaDAConfig, model: Optional[LLaDAModel] = None, init_params: bool = False):
|
| 1400 |
super().__init__(config)
|
|
|
|
| 1406 |
self.model = LLaDAModel(model_config, init_params=init_params)
|
| 1407 |
else:
|
| 1408 |
self.model = model
|
| 1409 |
+
self.post_init()
|
| 1410 |
|
| 1411 |
+
@can_return_tuple
|
| 1412 |
def forward(
|
| 1413 |
self,
|
| 1414 |
+
input_ids: torch.LongTensor | None = None,
|
| 1415 |
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 1416 |
attention_mask: Optional[torch.Tensor] = None,
|
| 1417 |
attention_bias: Optional[torch.Tensor] = None,
|
|
|
|
| 1420 |
use_cache: Optional[bool] = None,
|
| 1421 |
output_attentions: Optional[bool] = None,
|
| 1422 |
output_hidden_states: Optional[bool] = None,
|
| 1423 |
+
**kwargs
|
|
|
|
| 1424 |
) -> Union[Tuple, CausalLMOutputWithPast]:
|
| 1425 |
if use_cache is None:
|
| 1426 |
use_cache = self.config.use_cache
|
|
|
|
| 1428 |
if output_attentions:
|
| 1429 |
raise ValueError("output_attentions is not yet supported in LLaDA")
|
| 1430 |
|
|
|
|
| 1431 |
|
| 1432 |
# decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
|
| 1433 |
outputs = self.model.forward(
|
|
|
|
| 1443 |
logits = outputs.logits
|
| 1444 |
hidden_states = outputs.hidden_states
|
| 1445 |
|
|
|
|
| 1446 |
if labels is not None:
|
| 1447 |
import warnings
|
| 1448 |
warnings.warn("Note that for LLaDA, you cannot calculate the loss here.", UserWarning)
|
| 1449 |
+
|
|
|
|
|
|
|
|
|
|
| 1450 |
return CausalLMOutputWithPast(
|
| 1451 |
logits=logits,
|
| 1452 |
past_key_values=outputs.attn_key_values,
|
|
|
|
| 1496 |
else:
|
| 1497 |
self.model.transformer.ff_out = value
|
| 1498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1499 |
# Register the model so that it is available for transformer pipelines, auto-loading, etc.
|
| 1500 |
AutoModel.register(LLaDAConfig, LLaDAModelLM)
|