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/geometric_attention_final.py from Lanni-ni/alibi_2_4_256_pile_seed44: direct link, hf CLI and curl.
- Browser
- Download file 2.82 kB
-
https://huggingface.co/Lanni-ni/alibi_2_4_256_pile_seed44/resolve/main/ops/geometric_attention_final.py
- Command line
-
hf download hf://Lanni-ni/alibi_2_4_256_pile_seed44/ops/geometric_attention_final.py
-
curl -L -o geometric_attention_final.py https://huggingface.co/Lanni-ni/alibi_2_4_256_pile_seed44/resolve/main/ops/geometric_attention_final.py
2.82 kB
| """ | |
| Geometric Attention - CUDA加速版本 (支持FP16) | |
| """ | |
| import math | |
| import torch | |
| from einops import rearrange | |
| from typing import Optional | |
| # 尝试导入CUDA版本 | |
| try: | |
| from forgetting_transformer.ops.geometric_attention.cuda_interface import ( | |
| load_extension, | |
| geometric_attention_activation, | |
| ) | |
| load_extension() | |
| HAS_CUDA = True | |
| print("✅ Using CUDA geometric attention (with FP16 support)") | |
| except Exception as e: | |
| HAS_CUDA = False | |
| print(f"⚠️ CUDA not available: {e}") | |
| def geometric_attention_cuda( | |
| q: torch.Tensor, | |
| k: torch.Tensor, | |
| v: torch.Tensor, | |
| *, | |
| head_first: bool = False, | |
| seq_start: Optional[torch.Tensor] = None, | |
| sm_scale: Optional[float] = None, | |
| normalize: bool = True, | |
| ) -> torch.Tensor: | |
| if not HAS_CUDA: | |
| raise RuntimeError("CUDA not available") | |
| # ⭐ 保存原始dtype | |
| original_dtype = q.dtype | |
| needs_cast = original_dtype == torch.float16 | |
| # ⭐ 如果是FP16,转成FP32 | |
| if needs_cast: | |
| q = q.float() | |
| k = k.float() | |
| v = v.float() | |
| # Rearrange | |
| 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") | |
| B, H, T_q, D = q.shape | |
| if sm_scale is None: | |
| sm_scale = 1.0 / math.sqrt(D) | |
| # Attention scores | |
| logits = torch.matmul(q, k.transpose(-2, -1)) * sm_scale | |
| # CUDA kernel (FP32) | |
| attn_weights = geometric_attention_activation( | |
| logits, mask=None, pos_offset=0, normalize=normalize | |
| ) | |
| # Apply to values | |
| output = torch.matmul(attn_weights, v) | |
| # Rearrange back | |
| if not head_first: | |
| output = rearrange(output, "b h t d -> b t h d") | |
| # ⭐ 转回原始dtype | |
| if needs_cast: | |
| output = output.to(original_dtype) | |
| return output | |
| def geometric_attention( | |
| q: torch.Tensor, | |
| k: torch.Tensor, | |
| v: torch.Tensor, | |
| *, | |
| head_first: bool = False, | |
| seq_start: Optional[torch.Tensor] = None, | |
| sm_scale: Optional[float] = None, | |
| normalize: bool = True, | |
| ) -> torch.Tensor: | |
| """自动选择CUDA或Python""" | |
| if HAS_CUDA and q.is_cuda: | |
| try: | |
| return geometric_attention_cuda( | |
| q, k, v, head_first=head_first, | |
| seq_start=seq_start, sm_scale=sm_scale, | |
| normalize=normalize | |
| ) | |
| except Exception as e: | |
| # 不打印太多警告,会刷屏 | |
| pass | |
| # Fallback | |
| from forgetting_transformer.ops.geometric_attention_std import geometric_attention_std | |
| return geometric_attention_std( | |
| q, k, v, head_first=head_first, | |
| seq_start=seq_start, sm_scale=sm_scale, | |
| normalize=normalize | |
| ) | |