Text Generation
Transformers
Safetensors
English
sdar
feature-extraction
diffusion-lm
introspective-decoding
conversational
custom_code
Instructions to use yifanyu/I-DLM-8B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use yifanyu/I-DLM-8B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="yifanyu/I-DLM-8B", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("yifanyu/I-DLM-8B", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use yifanyu/I-DLM-8B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "yifanyu/I-DLM-8B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "yifanyu/I-DLM-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/yifanyu/I-DLM-8B
- SGLang
How to use yifanyu/I-DLM-8B 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 "yifanyu/I-DLM-8B" \ --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": "yifanyu/I-DLM-8B", "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 "yifanyu/I-DLM-8B" \ --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": "yifanyu/I-DLM-8B", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use yifanyu/I-DLM-8B with Docker Model Runner:
docker model run hf.co/yifanyu/I-DLM-8B
v5-align: remove store_kv; always update() on cached forward
Browse files- modeling_sdar.py +4 -33
modeling_sdar.py
CHANGED
|
@@ -261,37 +261,12 @@ class SDARAttention(nn.Module):
|
|
| 261 |
query_states, key_states = apply_rotary_pos_emb(
|
| 262 |
query_states, key_states, cos, sin)
|
| 263 |
|
| 264 |
-
#
|
| 265 |
-
#
|
| 266 |
-
# `
|
| 267 |
-
|
| 268 |
-
# still arrives here as `None` — treat that as "use config default" rather than False.
|
| 269 |
-
store_kv = kwargs.get("store_kv", None)
|
| 270 |
-
if store_kv is None:
|
| 271 |
-
store_kv = bool(getattr(self.config, "use_regular_causal", False))
|
| 272 |
-
if past_key_value is not None and store_kv:
|
| 273 |
-
# Store new kv into the cache (and get concatenated result).
|
| 274 |
key_states, value_states = past_key_value.update(
|
| 275 |
key_states, value_states, self.layer_idx)
|
| 276 |
-
elif past_key_value is not None and not store_kv and len(past_key_value) > self.layer_idx:
|
| 277 |
-
# Retrieve only (don't store): read cached kv and concatenate with current block kv.
|
| 278 |
-
# transformers v5 DynamicCache uses `.layers[idx].keys/.values`; v4 supports `cache[idx]`.
|
| 279 |
-
past_key_states = past_value_states = None
|
| 280 |
-
if hasattr(past_key_value, "layers"):
|
| 281 |
-
layer = past_key_value.layers[self.layer_idx]
|
| 282 |
-
past_key_states, past_value_states = layer.keys, layer.values
|
| 283 |
-
else:
|
| 284 |
-
try:
|
| 285 |
-
past_key_states, past_value_states = past_key_value[self.layer_idx]
|
| 286 |
-
except (IndexError, TypeError, KeyError):
|
| 287 |
-
past_key_states = past_value_states = None
|
| 288 |
-
# Guard: v5 DynamicCache has a layer slot from construction time but its `.keys` is None
|
| 289 |
-
# until the first `.update()` call. On the initial cached forward (e.g. plain `generate()`
|
| 290 |
-
# that hasn't stored this layer's KV yet), there's nothing to concatenate — just use the
|
| 291 |
-
# current block's KVs as if no cache.
|
| 292 |
-
if past_key_states is not None and past_value_states is not None:
|
| 293 |
-
key_states = torch.cat([past_key_states, key_states], dim=-2)
|
| 294 |
-
value_states = torch.cat([past_value_states, value_states], dim=-2)
|
| 295 |
|
| 296 |
attention_mask = attention_mask.bool() if attention_mask is not None else None
|
| 297 |
|
|
@@ -373,7 +348,6 @@ class SDARDecoderLayer(GradientCheckpointingLayer):
|
|
| 373 |
past_key_value: Optional[Cache] = None,
|
| 374 |
output_attentions: Optional[bool] = False,
|
| 375 |
use_cache: Optional[bool] = False,
|
| 376 |
-
store_kv: Optional[bool] = False,
|
| 377 |
cache_position: Optional[torch.LongTensor] = None,
|
| 378 |
# necessary, but kept here for BC
|
| 379 |
position_embeddings: Optional[Tuple[torch.Tensor,
|
|
@@ -391,7 +365,6 @@ class SDARDecoderLayer(GradientCheckpointingLayer):
|
|
| 391 |
past_key_value=past_key_value,
|
| 392 |
output_attentions=output_attentions,
|
| 393 |
use_cache=use_cache,
|
| 394 |
-
store_kv=store_kv,
|
| 395 |
cache_position=cache_position,
|
| 396 |
position_embeddings=position_embeddings,
|
| 397 |
**kwargs,
|
|
@@ -543,7 +516,6 @@ class SDARModel(SDARPreTrainedModel):
|
|
| 543 |
past_key_values: Optional[Cache] = None,
|
| 544 |
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 545 |
use_cache: Optional[bool] = None,
|
| 546 |
-
store_kv: Optional[bool] = None,
|
| 547 |
output_attentions: Optional[bool] = None,
|
| 548 |
output_hidden_states: Optional[bool] = None,
|
| 549 |
cache_position: Optional[torch.LongTensor] = None,
|
|
@@ -610,7 +582,6 @@ class SDARModel(SDARPreTrainedModel):
|
|
| 610 |
past_key_value=past_key_values,
|
| 611 |
output_attentions=output_attentions,
|
| 612 |
use_cache=use_cache,
|
| 613 |
-
store_kv=store_kv,
|
| 614 |
cache_position=cache_position,
|
| 615 |
position_embeddings=position_embeddings,
|
| 616 |
**flash_attn_kwargs,
|
|
|
|
| 261 |
query_states, key_states = apply_rotary_pos_emb(
|
| 262 |
query_states, key_states, cos, sin)
|
| 263 |
|
| 264 |
+
# Standard transformers v5 cache convention: when a cache is provided, always `.update()` it.
|
| 265 |
+
# Callers that want a read-only forward should pass `past_key_values=None`, or use
|
| 266 |
+
# `DynamicCache.crop(prev_seq_len)` to roll back the append after reading the logits.
|
| 267 |
+
if past_key_value is not None:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
key_states, value_states = past_key_value.update(
|
| 269 |
key_states, value_states, self.layer_idx)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 270 |
|
| 271 |
attention_mask = attention_mask.bool() if attention_mask is not None else None
|
| 272 |
|
|
|
|
| 348 |
past_key_value: Optional[Cache] = None,
|
| 349 |
output_attentions: Optional[bool] = False,
|
| 350 |
use_cache: Optional[bool] = False,
|
|
|
|
| 351 |
cache_position: Optional[torch.LongTensor] = None,
|
| 352 |
# necessary, but kept here for BC
|
| 353 |
position_embeddings: Optional[Tuple[torch.Tensor,
|
|
|
|
| 365 |
past_key_value=past_key_value,
|
| 366 |
output_attentions=output_attentions,
|
| 367 |
use_cache=use_cache,
|
|
|
|
| 368 |
cache_position=cache_position,
|
| 369 |
position_embeddings=position_embeddings,
|
| 370 |
**kwargs,
|
|
|
|
| 516 |
past_key_values: Optional[Cache] = None,
|
| 517 |
inputs_embeds: Optional[torch.FloatTensor] = None,
|
| 518 |
use_cache: Optional[bool] = None,
|
|
|
|
| 519 |
output_attentions: Optional[bool] = None,
|
| 520 |
output_hidden_states: Optional[bool] = None,
|
| 521 |
cache_position: Optional[torch.LongTensor] = None,
|
|
|
|
| 582 |
past_key_value=past_key_values,
|
| 583 |
output_attentions=output_attentions,
|
| 584 |
use_cache=use_cache,
|
|
|
|
| 585 |
cache_position=cache_position,
|
| 586 |
position_embeddings=position_embeddings,
|
| 587 |
**flash_attn_kwargs,
|