Text Generation
Transformers
Safetensors
English
Arabic
quasar_long
silx-ai
quasar-preview
quasar
foundation-model
Mixture of Experts
18b
2b-active
long-context
bittensor
sn24
decentralized-training
distillation
hybrid-transformer
loop-transformer
safe-nope
drope
conversational
custom_code
Instructions to use silx-ai/Quasar-Preview with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use silx-ai/Quasar-Preview with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="silx-ai/Quasar-Preview", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("silx-ai/Quasar-Preview", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use silx-ai/Quasar-Preview with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "silx-ai/Quasar-Preview" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "silx-ai/Quasar-Preview", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/silx-ai/Quasar-Preview
- SGLang
How to use silx-ai/Quasar-Preview 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 "silx-ai/Quasar-Preview" \ --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": "silx-ai/Quasar-Preview", "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 "silx-ai/Quasar-Preview" \ --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": "silx-ai/Quasar-Preview", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use silx-ai/Quasar-Preview with Docker Model Runner:
docker model run hf.co/silx-ai/Quasar-Preview
| # Copyright (c) 2023-2026, Songlin Yang, Yu Zhang | |
| import warnings | |
| import torch | |
| from fla.modules.l2norm import l2norm_bwd, l2norm_fwd | |
| from fla.ops.common.chunk_delta_h import chunk_gated_delta_rule_bwd_dhu, chunk_gated_delta_rule_fwd_h | |
| from fla.ops.common.chunk_o import chunk_bwd_dqkwg, chunk_bwd_dv_local, chunk_fwd_o | |
| from fla.ops.delta_rule.wy_fast import prepare_wy_repr_bwd, prepare_wy_repr_fwd, recompute_w_u_fwd | |
| from fla.ops.utils.index import prepare_chunk_indices | |
| from fla.utils import autocast_custom_bwd, autocast_custom_fwd, input_guard | |
| def chunk_delta_rule_fwd( | |
| q: torch.Tensor, | |
| k: torch.Tensor, | |
| v: torch.Tensor, | |
| beta: torch.Tensor, | |
| scale: float, | |
| initial_state: torch.Tensor, | |
| output_final_state: bool, | |
| cu_seqlens: torch.LongTensor | None = None, | |
| chunk_indices: torch.LongTensor | None = None, | |
| ): | |
| # obtain WY representation. u is actually the new v. | |
| w, u, A = prepare_wy_repr_fwd( | |
| k=k, | |
| v=v, | |
| beta=beta, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| h, v_new, final_state = chunk_gated_delta_rule_fwd_h( | |
| k=k, | |
| w=w, | |
| u=u, | |
| g=None, | |
| initial_state=initial_state, | |
| output_final_state=output_final_state, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| o = chunk_fwd_o( | |
| q=q, | |
| k=k, | |
| v=v_new, | |
| h=h, | |
| g=None, | |
| scale=scale, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| return o, A, final_state | |
| def chunk_delta_rule_bwd( | |
| q: torch.Tensor, | |
| k: torch.Tensor, | |
| v: torch.Tensor, | |
| beta: torch.Tensor, | |
| A: torch.Tensor, | |
| scale: float, | |
| initial_state: torch.Tensor, | |
| do: torch.Tensor, | |
| dht: torch.Tensor, | |
| cu_seqlens: torch.LongTensor | None = None, | |
| chunk_indices: torch.LongTensor | None = None, | |
| ): | |
| w, u = recompute_w_u_fwd( | |
| k=k, | |
| v=v, | |
| beta=beta, | |
| A=A, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| h, v_new, _ = chunk_gated_delta_rule_fwd_h( | |
| k=k, | |
| w=w, | |
| u=u, | |
| g=None, | |
| initial_state=initial_state, | |
| output_final_state=False, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| dv = chunk_bwd_dv_local( | |
| q=q, | |
| k=k, | |
| do=do, | |
| g=None, | |
| scale=scale, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| dh, dh0, dv = chunk_gated_delta_rule_bwd_dhu( | |
| q=q, | |
| k=k, | |
| w=w, | |
| g=None, | |
| h0=initial_state, | |
| dht=dht, | |
| do=do, | |
| dv=dv, | |
| scale=scale, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| dq, dk, dw, _ = chunk_bwd_dqkwg( | |
| q=q, | |
| k=k, | |
| v=v_new, | |
| h=h, | |
| w=w, | |
| dv=dv, | |
| do=do, | |
| dh=dh, | |
| g=None, | |
| scale=scale, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| dk2, dv, db = prepare_wy_repr_bwd( | |
| k=k, | |
| v=v, | |
| beta=beta, | |
| A=A, | |
| dw=dw, | |
| du=dv, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| dk.add_(dk2) | |
| return dq, dk, dv, db, dh0 | |
| class ChunkDeltaRuleFunction(torch.autograd.Function): | |
| def forward( | |
| ctx, | |
| q: torch.Tensor, | |
| k: torch.Tensor, | |
| v: torch.Tensor, | |
| beta: torch.Tensor, | |
| scale: float, | |
| initial_state: torch.Tensor, | |
| output_final_state: bool, | |
| use_qk_l2norm_in_kernel: bool = False, | |
| cu_seqlens: torch.LongTensor | None = None, | |
| cu_seqlens_cpu: torch.LongTensor | None = None, | |
| ): | |
| if use_qk_l2norm_in_kernel: | |
| q, q_rstd = l2norm_fwd(q) | |
| k, k_rstd = l2norm_fwd(k) | |
| else: | |
| q_rstd, k_rstd = None, None | |
| chunk_indices = prepare_chunk_indices( | |
| cu_seqlens, 64, cu_seqlens_cpu=cu_seqlens_cpu) if cu_seqlens is not None else None | |
| o, A, final_state = chunk_delta_rule_fwd( | |
| q=q, | |
| k=k, | |
| v=v, | |
| beta=beta, | |
| scale=scale, | |
| initial_state=initial_state, | |
| output_final_state=output_final_state, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| ctx.save_for_backward(q, q_rstd, k, k_rstd, v, beta, A, initial_state, cu_seqlens, chunk_indices) | |
| ctx.scale = scale | |
| ctx.use_qk_l2norm_in_kernel = use_qk_l2norm_in_kernel | |
| return o.to(q.dtype), final_state | |
| def backward( | |
| ctx, | |
| do: torch.Tensor, | |
| dht: torch.Tensor, | |
| ): | |
| q, q_rstd, k, k_rstd, v, beta, A, initial_state, cu_seqlens, chunk_indices = ctx.saved_tensors | |
| dq, dk, dv, db, dh0 = chunk_delta_rule_bwd( | |
| q=q, | |
| k=k, | |
| v=v, | |
| beta=beta, | |
| A=A, | |
| scale=ctx.scale, | |
| initial_state=initial_state, | |
| do=do, | |
| dht=dht, | |
| cu_seqlens=cu_seqlens, | |
| chunk_indices=chunk_indices, | |
| ) | |
| if ctx.use_qk_l2norm_in_kernel: | |
| dq = l2norm_bwd(q, q_rstd, dq) | |
| dk = l2norm_bwd(k, k_rstd, dk) | |
| return dq.to(q.dtype), dk.to(k.dtype), dv.to(v.dtype), db.to(beta.dtype), None, dh0, None, None, None, None | |
| def chunk_delta_rule( | |
| q: torch.Tensor, | |
| k: torch.Tensor, | |
| v: torch.Tensor, | |
| beta: torch.Tensor, | |
| scale: float = None, | |
| initial_state: torch.Tensor = None, | |
| output_final_state: bool = False, | |
| use_qk_l2norm_in_kernel: bool = False, | |
| cu_seqlens: torch.LongTensor | None = None, | |
| cu_seqlens_cpu: torch.LongTensor | None = None, | |
| head_first: bool = False, | |
| ): | |
| r""" | |
| Args: | |
| q (torch.Tensor): | |
| queries of shape `[B, T, H, K]`. | |
| k (torch.Tensor): | |
| keys of shape `[B, T, H, K]`. | |
| v (torch.Tensor): | |
| values of shape `[B, T, H, V]`. | |
| beta (torch.Tensor): | |
| betas of shape `[B, T, H]`. | |
| scale (Optional[float]): | |
| Scale factor for the RetNet attention scores. | |
| If not provided, it will default to `1 / sqrt(K)`. Default: `None`. | |
| initial_state (Optional[torch.Tensor]): | |
| Initial state of shape `[N, H, K, V]` for `N` input sequences. | |
| For equal-length input sequences, `N` equals the batch size `B`. | |
| Default: `None`. | |
| output_final_state (Optional[bool]): | |
| Whether to output the final state of shape `[N, H, K, V]`. Default: `False`. | |
| use_qk_l2norm_in_kernel (Optional[bool]): | |
| Whether to use qk l2norm within the kernel for saving GPU memory. | |
| Default: `False`. | |
| cu_seqlens (torch.LongTensor): | |
| Cumulative sequence lengths of shape `[N+1]` used for variable-length training, | |
| consistent with the FlashAttention API. | |
| head_first (Optional[bool]): | |
| Whether the inputs are in the head-first format. Default: `False`. | |
| This argument has been deprecated. | |
| Returns: | |
| o (torch.Tensor): | |
| Outputs of shape `[B, T, H, V]`. | |
| final_state (torch.Tensor): | |
| Final state of shape `[N, H, K, V]` if `output_final_state=True` else `None`. | |
| Examples:: | |
| >>> import torch | |
| >>> import torch.nn.functional as F | |
| >>> from einops import rearrange | |
| >>> from fla.ops.delta_rule import chunk_delta_rule | |
| # inputs with equal lengths | |
| >>> B, T, H, K, V = 4, 2048, 4, 512, 512 | |
| >>> q = torch.randn(B, T, H, K, dtype=torch.bfloat16, device='cuda') | |
| >>> k = F.normalize(torch.randn(B, T, H, K, dtype=torch.bfloat16, device='cuda'), p=2, dim=-1) | |
| >>> v = torch.randn(B, T, H, V, dtype=torch.bfloat16, device='cuda') | |
| >>> beta = torch.rand(B, T, H, dtype=torch.bfloat16, device='cuda').sigmoid() | |
| >>> h0 = torch.randn(B, H, K, V, dtype=torch.bfloat16, device='cuda') | |
| >>> o, ht = chunk_delta_rule( | |
| q, k, v, beta, | |
| initial_state=h0, | |
| output_final_state=True | |
| ) | |
| # for variable-length inputs, the batch size `B` is expected to be 1 and `cu_seqlens` is required | |
| >>> q, k, v, beta = map(lambda x: rearrange(x, 'b t ... -> 1 (b t) ...'), (q, k, v, beta)) | |
| # for a batch with 4 sequences, `cu_seqlens` with 5 start/end positions are expected | |
| >>> cu_seqlens = q.new_tensor([0, 2048, 4096, 6144, 8192], dtype=torch.long) | |
| >>> o, ht = chunk_delta_rule( | |
| q, k, v, beta, | |
| initial_state=h0, | |
| output_final_state=True, | |
| cu_seqlens=cu_seqlens | |
| ) | |
| """ | |
| assert q.dtype == k.dtype == v.dtype | |
| assert q.dtype != torch.float32, "ChunkDeltaRuleFunction does not support float32. Please use bfloat16." | |
| assert len(beta.shape) == 3, "beta must be of shape (batch size, num of head, seq len)." | |
| if head_first: | |
| raise DeprecationWarning( | |
| "head_first is deprecated and will be removed in a future version. " | |
| "Please use head_first=False for now instead.", | |
| ) | |
| if not head_first and q.shape[1] < q.shape[2]: | |
| warnings.warn( | |
| f"Input tensor shape suggests potential format mismatch: seq_len ({q.shape[1]}) < num_heads ({q.shape[2]}). " | |
| "This may indicate the inputs were passed in head-first format [B, H, T, ...] " | |
| "when head_first=False was specified. " | |
| "Please verify your input tensor format matches the expected shape [B, T, H, ...].", | |
| ) | |
| if cu_seqlens is not None: | |
| if q.shape[0] != 1: | |
| raise ValueError( | |
| f"The batch size is expected to be 1 rather than {q.shape[0]} when using `cu_seqlens`." | |
| f"Please flatten variable-length inputs before processing.", | |
| ) | |
| if initial_state is not None and initial_state.shape[0] != len(cu_seqlens) - 1: | |
| raise ValueError( | |
| f"The number of initial states is expected to be equal to the number of input sequences, " | |
| f"i.e., {len(cu_seqlens) - 1} rather than {initial_state.shape[0]}.", | |
| ) | |
| scale = k.shape[-1] ** -0.5 if scale is None else scale | |
| o, final_state = ChunkDeltaRuleFunction.apply( | |
| q, | |
| k, | |
| v, | |
| beta, | |
| scale, | |
| initial_state, | |
| output_final_state, | |
| use_qk_l2norm_in_kernel, | |
| cu_seqlens, | |
| cu_seqlens_cpu, | |
| ) | |
| return o, final_state | |