Instructions to use Lanni-ni/alibi_2_4_256_pile_seed44 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Lanni-ni/alibi_2_4_256_pile_seed44 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Lanni-ni/alibi_2_4_256_pile_seed44", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("Lanni-ni/alibi_2_4_256_pile_seed44", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Lanni-ni/alibi_2_4_256_pile_seed44 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Lanni-ni/alibi_2_4_256_pile_seed44" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Lanni-ni/alibi_2_4_256_pile_seed44", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/Lanni-ni/alibi_2_4_256_pile_seed44
- SGLang
How to use Lanni-ni/alibi_2_4_256_pile_seed44 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 "Lanni-ni/alibi_2_4_256_pile_seed44" \ --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": "Lanni-ni/alibi_2_4_256_pile_seed44", "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 "Lanni-ni/alibi_2_4_256_pile_seed44" \ --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": "Lanni-ni/alibi_2_4_256_pile_seed44", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use Lanni-ni/alibi_2_4_256_pile_seed44 with Docker Model Runner:
docker model run hf.co/Lanni-ni/alibi_2_4_256_pile_seed44
Download ops/forgetting_attention_std.py from Lanni-ni/alibi_2_4_256_pile_seed44: direct link, hf CLI and curl.
- Browser
- Download file 1.95 kB
-
https://huggingface.co/Lanni-ni/alibi_2_4_256_pile_seed44/resolve/main/ops/forgetting_attention_std.py
- Command line
-
hf download hf://Lanni-ni/alibi_2_4_256_pile_seed44/ops/forgetting_attention_std.py
-
curl -L -o forgetting_attention_std.py https://huggingface.co/Lanni-ni/alibi_2_4_256_pile_seed44/resolve/main/ops/forgetting_attention_std.py
1.95 kB
| import math | |
| import torch | |
| import torch.nn.functional as F | |
| from einops import rearrange | |
| from typing import Optional | |
| def forgetting_attention_std( | |
| q: torch.Tensor, | |
| k: torch.Tensor, | |
| v: torch.Tensor, | |
| log_fgate: torch.Tensor, | |
| *, | |
| head_first: bool = False, | |
| seq_start: Optional[torch.Tensor] = None, | |
| sm_scale: Optional[float] = None, | |
| ) -> torch.Tensor: | |
| if not head_first: | |
| q = rearrange(q, "b t h d -> b h t d") | |
| k = rearrange(k, "b t h d -> b h t d") | |
| v = rearrange(v, "b t h d -> b h t d") | |
| log_fgate = rearrange(log_fgate, "b t h -> b h t") | |
| B, H, T_q, D = q.shape | |
| T_k = k.shape[2] | |
| if sm_scale is None: | |
| sm_scale = 1.0 / math.sqrt(D) | |
| scores = torch.matmul(q.float(), k.float().transpose(-2, -1)) * sm_scale | |
| log_fgate_masked = log_fgate.float() | |
| if seq_start is not None: | |
| log_fgate_masked = log_fgate_masked.clone() | |
| mask_idx = torch.arange(T_k, device=q.device)[None, None, :] < seq_start[:, None, None] | |
| log_fgate_masked[mask_idx] = 0.0 | |
| log_lambda = torch.cumsum(log_fgate_masked, dim=-1) | |
| decay_bias = log_lambda[:, :, :T_q, None] - log_lambda[:, :, None, :] | |
| scores = scores + decay_bias | |
| # Causal mask | |
| P_SEQ = T_k - T_q | |
| causal_mask = torch.triu(torch.ones((T_q, T_k), dtype=torch.bool, device=q.device), diagonal=P_SEQ + 1) | |
| scores = scores.masked_fill(causal_mask[None, None, :, :], float('-inf')) | |
| # seq_start mask | |
| if seq_start is not None: | |
| seq_mask = torch.arange(T_k, device=q.device)[None, None, None, :] < seq_start[None, :, None, None] | |
| scores = scores.masked_fill(seq_mask, float('-inf')) | |
| # Softmax | |
| attn = F.softmax(scores, dim=-1) | |
| attn = torch.nan_to_num(attn, 0.0) | |
| out = torch.matmul(attn.to(v.dtype), v) | |
| if not head_first: | |
| out = rearrange(out, "b h t d -> b t h d") | |
| return out | |