Instructions to use RWKV-Red-Team/ARWKV-7B-Preview-0.1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use RWKV-Red-Team/ARWKV-7B-Preview-0.1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="RWKV-Red-Team/ARWKV-7B-Preview-0.1", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("RWKV-Red-Team/ARWKV-7B-Preview-0.1", trust_remote_code=True, dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use RWKV-Red-Team/ARWKV-7B-Preview-0.1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "RWKV-Red-Team/ARWKV-7B-Preview-0.1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "RWKV-Red-Team/ARWKV-7B-Preview-0.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/RWKV-Red-Team/ARWKV-7B-Preview-0.1
- SGLang
How to use RWKV-Red-Team/ARWKV-7B-Preview-0.1 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 "RWKV-Red-Team/ARWKV-7B-Preview-0.1" \ --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": "RWKV-Red-Team/ARWKV-7B-Preview-0.1", "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 "RWKV-Red-Team/ARWKV-7B-Preview-0.1" \ --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": "RWKV-Red-Team/ARWKV-7B-Preview-0.1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use RWKV-Red-Team/ARWKV-7B-Preview-0.1 with Docker Model Runner:
docker model run hf.co/RWKV-Red-Team/ARWKV-7B-Preview-0.1
File size: 2,275 Bytes
c1a12af 3736a38 c1a12af 3736a38 c1a12af 3736a38 c1a12af 3736a38 c1a12af 3736a38 c1a12af 3736a38 c1a12af 3736a38 c1a12af 3736a38 c1a12af | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | import torch
from typing import Any, Dict, Optional, Union
from transformers.cache_utils import DynamicCache
class AttnState:
def __init__(self, shift_state: torch.Tensor, wkv_state: torch.Tensor):
self.shift_state = shift_state
self.wkv_state = wkv_state
class FfnState:
def __init__(self, shift_state: torch.Tensor):
self.shift_state = shift_state
class BlockState:
def __init__(
self,
attn_state: AttnState,
ffn_state: FfnState
):
self.attn_state = attn_state
self.ffn_state = ffn_state
class HybridCache(DynamicCache):
def __init__(self) -> None:
super().__init__()
self.rwkv_layers = set()
self.key_cache_nums = 0
self.v_first_cache = None
def update(
self,
key_states: Union[int, torch.Tensor],
value_states: Union[torch.Tensor, BlockState],
layer_idx: int,
cache_kwargs: Optional[Dict[str, Any]] = None
):
if isinstance(key_states, int) and isinstance(value_states, BlockState):
self.rwkv_layers.add(layer_idx)
if layer_idx >= self.key_cache_nums:
self.key_cache.append([])
self.value_cache.append([])
self.key_cache[layer_idx].append(key_states)
self.value_cache[layer_idx].append(value_states)
self.key_cache_nums += 1
else:
self.key_cache[layer_idx][0] += key_states
self.value_cache[layer_idx][0] = value_states
return key_states, value_states
return super().update(key_states, value_states, layer_idx, cache_kwargs)
def update_v_first(self, v_first: torch.Tensor):
self.v_first_cache = v_first
def get_v_first(self):
return self.v_first_cache
def get_seq_length(self, layer_idx: Optional[int] = 0):
if layer_idx in self.rwkv_layers:
return self.key_cache[layer_idx][0]
return super().get_seq_length(layer_idx)
def reorder_cache(self, beam_idx):
return super().reorder_cache(beam_idx)
def __getitem__(self, item):
if item in self.rwkv_layers:
return self.value_cache[item]
return super().__getitem__(item)
|