Text Generation
Transformers
Safetensors
llada2_moe
dllm
diffusion
llm
text_generation
conversational
custom_code
Instructions to use inclusionAI/LLaDA2.1-mini with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use inclusionAI/LLaDA2.1-mini with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="inclusionAI/LLaDA2.1-mini", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("inclusionAI/LLaDA2.1-mini", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use inclusionAI/LLaDA2.1-mini with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "inclusionAI/LLaDA2.1-mini" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "inclusionAI/LLaDA2.1-mini", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/inclusionAI/LLaDA2.1-mini
- SGLang
How to use inclusionAI/LLaDA2.1-mini 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 "inclusionAI/LLaDA2.1-mini" \ --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": "inclusionAI/LLaDA2.1-mini", "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 "inclusionAI/LLaDA2.1-mini" \ --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": "inclusionAI/LLaDA2.1-mini", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use inclusionAI/LLaDA2.1-mini with Docker Model Runner:
docker model run hf.co/inclusionAI/LLaDA2.1-mini
Use create_bidirectional_mask for backend-agnostic attention mask handling (SDPA, FA2, flex)
Browse files- modeling_llada2_moe.py +6 -14
modeling_llada2_moe.py
CHANGED
|
@@ -28,9 +28,7 @@ from torch.nn import CrossEntropyLoss
|
|
| 28 |
|
| 29 |
from transformers.activations import ACT2FN
|
| 30 |
from transformers.cache_utils import Cache, DynamicCache
|
| 31 |
-
from transformers.
|
| 32 |
-
_prepare_4d_causal_attention_mask_for_sdpa,
|
| 33 |
-
)
|
| 34 |
from transformers.modeling_outputs import (
|
| 35 |
MoeModelOutputWithPast,
|
| 36 |
MoeCausalLMOutputWithPast,
|
|
@@ -876,17 +874,11 @@ class LLaDA2MoeModel(LLaDA2MoePreTrainedModel):
|
|
| 876 |
device=inputs_embeds.device,
|
| 877 |
)
|
| 878 |
position_ids = position_ids.unsqueeze(0)
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
past_seen_tokens,
|
| 885 |
-
)
|
| 886 |
-
else:
|
| 887 |
-
raise ValueError(
|
| 888 |
-
f"LLaDA2.0 only support block attention mask with shape: {(batch_size, 1, seq_length, seq_length)}, the input attention with shape {attention_mask.size()=}!"
|
| 889 |
-
)
|
| 890 |
# embed positions
|
| 891 |
hidden_states = inputs_embeds
|
| 892 |
|
|
|
|
| 28 |
|
| 29 |
from transformers.activations import ACT2FN
|
| 30 |
from transformers.cache_utils import Cache, DynamicCache
|
| 31 |
+
from transformers.masking_utils import create_bidirectional_mask
|
|
|
|
|
|
|
| 32 |
from transformers.modeling_outputs import (
|
| 33 |
MoeModelOutputWithPast,
|
| 34 |
MoeCausalLMOutputWithPast,
|
|
|
|
| 874 |
device=inputs_embeds.device,
|
| 875 |
)
|
| 876 |
position_ids = position_ids.unsqueeze(0)
|
| 877 |
+
attention_mask = create_bidirectional_mask(
|
| 878 |
+
config=self.config,
|
| 879 |
+
inputs_embeds=inputs_embeds,
|
| 880 |
+
attention_mask=attention_mask,
|
| 881 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 882 |
# embed positions
|
| 883 |
hidden_states = inputs_embeds
|
| 884 |
|