Instructions to use JetLM/SDAR-1.7B-Chat with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use JetLM/SDAR-1.7B-Chat with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="JetLM/SDAR-1.7B-Chat", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("JetLM/SDAR-1.7B-Chat", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use JetLM/SDAR-1.7B-Chat with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "JetLM/SDAR-1.7B-Chat" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "JetLM/SDAR-1.7B-Chat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/JetLM/SDAR-1.7B-Chat
- SGLang
How to use JetLM/SDAR-1.7B-Chat 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 "JetLM/SDAR-1.7B-Chat" \ --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": "JetLM/SDAR-1.7B-Chat", "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 "JetLM/SDAR-1.7B-Chat" \ --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": "JetLM/SDAR-1.7B-Chat", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use JetLM/SDAR-1.7B-Chat with Docker Model Runner:
docker model run hf.co/JetLM/SDAR-1.7B-Chat
Restore store_kv vs retrieve-only split: use layers[idx] for v5 retrieve path
Browse files- modeling_sdar.py +12 -13
modeling_sdar.py
CHANGED
|
@@ -261,21 +261,20 @@ class SDARAttention(nn.Module):
|
|
| 261 |
query_states, key_states = apply_rotary_pos_emb(
|
| 262 |
query_states, key_states, cos, sin)
|
| 263 |
|
| 264 |
-
if past_key_value is not None:
|
| 265 |
-
#
|
| 266 |
-
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
| 268 |
if hasattr(past_key_value, "layers"):
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
elif kwargs.get("store_kv", False):
|
| 273 |
-
key_states, value_states = past_key_value.update(
|
| 274 |
-
key_states, value_states, self.layer_idx)
|
| 275 |
-
elif not kwargs.get("store_kv", False) and len(past_key_value) > self.layer_idx:
|
| 276 |
past_key_states, past_value_states = past_key_value[self.layer_idx]
|
| 277 |
-
|
| 278 |
-
|
| 279 |
|
| 280 |
attention_mask = attention_mask.bool() if attention_mask is not None else None
|
| 281 |
if torch.all(attention_mask): # decoding
|
|
|
|
| 261 |
query_states, key_states = apply_rotary_pos_emb(
|
| 262 |
query_states, key_states, cos, sin)
|
| 263 |
|
| 264 |
+
if past_key_value is not None and kwargs.get("store_kv", False):
|
| 265 |
+
# Store new kv into the cache (and get concatenated result).
|
| 266 |
+
key_states, value_states = past_key_value.update(
|
| 267 |
+
key_states, value_states, self.layer_idx)
|
| 268 |
+
elif past_key_value is not None and not kwargs.get("store_kv", False) and len(past_key_value) > self.layer_idx:
|
| 269 |
+
# Retrieve only (don't store): read cached kv and concatenate with current block kv.
|
| 270 |
+
# transformers v5 DynamicCache uses `.layers[idx].keys/.values`; v4 supports `cache[idx]`.
|
| 271 |
if hasattr(past_key_value, "layers"):
|
| 272 |
+
layer = past_key_value.layers[self.layer_idx]
|
| 273 |
+
past_key_states, past_value_states = layer.keys, layer.values
|
| 274 |
+
else:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 275 |
past_key_states, past_value_states = past_key_value[self.layer_idx]
|
| 276 |
+
key_states = torch.cat([past_key_states, key_states], dim=-2)
|
| 277 |
+
value_states = torch.cat([past_value_states, value_states], dim=-2)
|
| 278 |
|
| 279 |
attention_mask = attention_mask.bool() if attention_mask is not None else None
|
| 280 |
if torch.all(attention_mask): # decoding
|