Instructions to use smcleish/Recurrent-Llama-3.2-untrained with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use smcleish/Recurrent-Llama-3.2-untrained with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="smcleish/Recurrent-Llama-3.2-untrained", trust_remote_code=True)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("smcleish/Recurrent-Llama-3.2-untrained", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use smcleish/Recurrent-Llama-3.2-untrained with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "smcleish/Recurrent-Llama-3.2-untrained" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "smcleish/Recurrent-Llama-3.2-untrained", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/smcleish/Recurrent-Llama-3.2-untrained
- SGLang
How to use smcleish/Recurrent-Llama-3.2-untrained 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 "smcleish/Recurrent-Llama-3.2-untrained" \ --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": "smcleish/Recurrent-Llama-3.2-untrained", "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 "smcleish/Recurrent-Llama-3.2-untrained" \ --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": "smcleish/Recurrent-Llama-3.2-untrained", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use smcleish/Recurrent-Llama-3.2-untrained with Docker Model Runner:
docker model run hf.co/smcleish/Recurrent-Llama-3.2-untrained
Update raven_modeling_minimal.py
Browse files- raven_modeling_minimal.py +5 -10
raven_modeling_minimal.py
CHANGED
|
@@ -22,7 +22,7 @@ import torch.nn.functional as F
|
|
| 22 |
from transformers import GenerationConfig
|
| 23 |
from transformers.models.llama.modeling_llama import LlamaRotaryEmbedding, apply_rotary_pos_emb
|
| 24 |
|
| 25 |
-
torch.backends.cuda.enable_math_sdp(False)
|
| 26 |
|
| 27 |
|
| 28 |
class RavenPreTrainedModel(PreTrainedModel):
|
|
@@ -419,16 +419,11 @@ class CausalSelfAttention(torch.nn.Module):
|
|
| 419 |
if q.shape[2] < k.shape[2]:
|
| 420 |
if q.shape[2] > 1:
|
| 421 |
bias = attn_bias.causal_lower_right(q.shape[2], k.shape[2])
|
| 422 |
-
y = torch.nn.functional.scaled_dot_product_attention(q, k, v, bias, dropout_p=0.0)
|
| 423 |
else:
|
| 424 |
-
y = torch.nn.functional.scaled_dot_product_attention(q, k, v, dropout_p=0.0, is_causal=False)
|
| 425 |
else:
|
| 426 |
-
|
| 427 |
-
repeat_factor = self.n_head // self.n_kv_heads
|
| 428 |
-
k = k.repeat_interleave(repeat_factor, dim=1)
|
| 429 |
-
v = v.repeat_interleave(repeat_factor, dim=1)
|
| 430 |
-
|
| 431 |
-
y = torch.nn.functional.scaled_dot_product_attention(q, k, v, dropout_p=0.0, is_causal=True)
|
| 432 |
y = y.transpose(1, 2).reshape(B, S, E).contiguous() # reshape is a view if possible (it mostly is)
|
| 433 |
return self.proj(y)
|
| 434 |
|
|
@@ -651,7 +646,7 @@ class RavenForCausalLM(RavenPreTrainedModel, GenerationMixin):
|
|
| 651 |
if position_ids is None and cache_position is None:
|
| 652 |
position_ids = torch.arange(input_ids.shape[1], device=self.device).unsqueeze(0)
|
| 653 |
elif cache_position is not None:
|
| 654 |
-
position_ids =
|
| 655 |
|
| 656 |
if input_embeds is None:
|
| 657 |
input_embeds = self.transformer.wte(input_ids) # type: ignore # types broken in 2.6+
|
|
|
|
| 22 |
from transformers import GenerationConfig
|
| 23 |
from transformers.models.llama.modeling_llama import LlamaRotaryEmbedding, apply_rotary_pos_emb
|
| 24 |
|
| 25 |
+
# torch.backends.cuda.enable_math_sdp(False)
|
| 26 |
|
| 27 |
|
| 28 |
class RavenPreTrainedModel(PreTrainedModel):
|
|
|
|
| 419 |
if q.shape[2] < k.shape[2]:
|
| 420 |
if q.shape[2] > 1:
|
| 421 |
bias = attn_bias.causal_lower_right(q.shape[2], k.shape[2])
|
| 422 |
+
y = torch.nn.functional.scaled_dot_product_attention(q, k, v, bias, dropout_p=0.0, enable_gqa=True)
|
| 423 |
else:
|
| 424 |
+
y = torch.nn.functional.scaled_dot_product_attention(q, k, v, dropout_p=0.0, is_causal=False, enable_gqa=True)
|
| 425 |
else:
|
| 426 |
+
y = torch.nn.functional.scaled_dot_product_attention(q, k, v, dropout_p=0.0, is_causal=True, enable_gqa=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
y = y.transpose(1, 2).reshape(B, S, E).contiguous() # reshape is a view if possible (it mostly is)
|
| 428 |
return self.proj(y)
|
| 429 |
|
|
|
|
| 646 |
if position_ids is None and cache_position is None:
|
| 647 |
position_ids = torch.arange(input_ids.shape[1], device=self.device).unsqueeze(0)
|
| 648 |
elif cache_position is not None:
|
| 649 |
+
position_ids = cache_position.unsqueeze(0)
|
| 650 |
|
| 651 |
if input_embeds is None:
|
| 652 |
input_embeds = self.transformer.wte(input_ids) # type: ignore # types broken in 2.6+
|