Spaces:
Sleeping
Sleeping
Alic-Li commited on
Commit ·
bf12807
1
Parent(s): 60e9397
update rwkv_lightning_cuda backend
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitignore +0 -1
- .python-version +1 -1
- Dockerfile +0 -62
- README.md +0 -32
- api_types.py +0 -82
- app.py +242 -717
- config.production-modelscope.yaml +0 -68
- config.production.yaml +0 -73
- config.py +0 -84
- cuda/gemm_fp16_cublas.cpp +0 -75
- cuda/operators.cu +0 -246
- cuda/rwkv5.cu +0 -88
- cuda/rwkv5_op.cpp +0 -34
- cuda/rwkv6.cu +0 -87
- cuda/rwkv6_op.cpp +0 -34
- cuda/rwkv7.cu +0 -77
- cuda/rwkv7_op.cpp +0 -26
- cuda/wrapper.cpp +0 -141
- dist/assets/CodeHighlight-B5gv0P8p.css +1 -0
- dist/assets/CodeHighlight-DL4bOcf6.js +0 -0
- dist/assets/Input-CsAcNC8W.css +1 -0
- dist/assets/Input-o9Y44Uso.js +62 -0
- dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2 +0 -0
- dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff +0 -0
- dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf +0 -0
- dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf +0 -0
- dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff +0 -0
- dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2 +0 -0
- dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff +0 -0
- dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2 +0 -0
- dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf +0 -0
- dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf +0 -0
- dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff +0 -0
- dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2 +0 -0
- dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf +0 -0
- dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2 +0 -0
- dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff +0 -0
- dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2 +0 -0
- dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff +0 -0
- dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf +0 -0
- dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2 +0 -0
- dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf +0 -0
- dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff +0 -0
- dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf +0 -0
- dist/assets/KaTeX_Main-Italic-BMLOBm91.woff +0 -0
- dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2 +0 -0
- dist/assets/KaTeX_Main-Regular-B22Nviop.woff2 +0 -0
- dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff +0 -0
- dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf +0 -0
- dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf +0 -0
.gitignore
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
__pycache__/
|
| 3 |
*.py[oc]
|
| 4 |
build/
|
| 5 |
-
dist/
|
| 6 |
wheels/
|
| 7 |
*.egg-info
|
| 8 |
|
|
|
|
| 2 |
__pycache__/
|
| 3 |
*.py[oc]
|
| 4 |
build/
|
|
|
|
| 5 |
wheels/
|
| 6 |
*.egg-info
|
| 7 |
|
.python-version
CHANGED
|
@@ -1 +1 @@
|
|
| 1 |
-
3.
|
|
|
|
| 1 |
+
3.12
|
Dockerfile
DELETED
|
@@ -1,62 +0,0 @@
|
|
| 1 |
-
FROM node:20-alpine AS FrontendBuilder
|
| 2 |
-
|
| 3 |
-
RUN apk update && apk upgrade && \
|
| 4 |
-
apk add --no-cache bash git openssh curl rust cargo
|
| 5 |
-
|
| 6 |
-
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
|
| 7 |
-
RUN npm install -g pnpm
|
| 8 |
-
|
| 9 |
-
ADD https://api.github.com/repos/SolomonLeon/web-rwkv-realweb/git/refs/heads/ version_1.json
|
| 10 |
-
|
| 11 |
-
WORKDIR /app
|
| 12 |
-
RUN git clone https://github.com/SolomonLeon/web-rwkv-realweb.git /app
|
| 13 |
-
|
| 14 |
-
WORKDIR /app/web-rwkv-wasm
|
| 15 |
-
RUN ["cargo", "install", "wasm-pack", "--locked"]
|
| 16 |
-
|
| 17 |
-
WORKDIR /app
|
| 18 |
-
ENV PATH=/root/.cargo/bin:$PATH
|
| 19 |
-
RUN pnpm install
|
| 20 |
-
RUN if [ "$MODELSCOPE_ENVIRONMENT" = "studio" ]; then \
|
| 21 |
-
pnpm run build --mode target-rwkv-modelscope-space; \
|
| 22 |
-
else \
|
| 23 |
-
pnpm run build --mode target-rwkv-hf-space; \
|
| 24 |
-
fi
|
| 25 |
-
|
| 26 |
-
FROM nvidia/cuda:12.4.0-devel-ubuntu22.04 AS Backend
|
| 27 |
-
|
| 28 |
-
RUN <<EOF
|
| 29 |
-
apt update
|
| 30 |
-
apt install --no-install-recommends -y \
|
| 31 |
-
build-essential \
|
| 32 |
-
git \
|
| 33 |
-
cuda-nvcc-12-4 \
|
| 34 |
-
cuda-cudart-dev-12-4 \
|
| 35 |
-
python3-dev \
|
| 36 |
-
python3-pip \
|
| 37 |
-
libpython3.10-dev
|
| 38 |
-
apt clean && rm -rf /var/lib/apt/lists/*
|
| 39 |
-
EOF
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
|
| 43 |
-
|
| 44 |
-
COPY . .
|
| 45 |
-
|
| 46 |
-
RUN useradd -m -u 1000 user
|
| 47 |
-
USER user
|
| 48 |
-
|
| 49 |
-
ENV HOME=/home/user \
|
| 50 |
-
PATH=/usr/local/cuda/bin:/home/user/.local/bin:$PATH \
|
| 51 |
-
LD_LIBRARY_PATH="/usr/local/cuda/lib64:${LD_LIBRARY_PATH}" \
|
| 52 |
-
CXX=/usr/bin/g++ \
|
| 53 |
-
TORCH_CUDA_ARCH_LIST="7.5"
|
| 54 |
-
WORKDIR $HOME/app
|
| 55 |
-
|
| 56 |
-
COPY --chown=user . $HOME/app
|
| 57 |
-
|
| 58 |
-
COPY --chown=user --from=FrontendBuilder /app/dist $HOME/app/dist-frontend
|
| 59 |
-
|
| 60 |
-
RUN uv sync --frozen --extra cu124
|
| 61 |
-
|
| 62 |
-
CMD ["sh", "-c", "if [ \"$MODELSCOPE_ENVIRONMENT\" = \"studio\" ]; then CONFIG_FILE=\"./config.production-modelscope.yaml\"; else CONFIG_FILE=\"./config.production.yaml\"; fi; uv run --offline --frozen app.py --config_file \"$CONFIG_FILE\""]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
README.md
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
---
|
| 2 |
-
|
| 3 |
-
title: RWKV HF Space
|
| 4 |
-
emoji: 🐦⬛
|
| 5 |
-
colorFrom: purple
|
| 6 |
-
colorTo: pink
|
| 7 |
-
sdk: docker
|
| 8 |
-
pinned: false
|
| 9 |
-
|
| 10 |
-
---
|
| 11 |
-
|
| 12 |
-
# Simple RWKV OpenAI-Compatible API
|
| 13 |
-
|
| 14 |
-
## Usage
|
| 15 |
-
|
| 16 |
-
`RWKV-x070-World-0.1B-v2.8-20241210-ctx4096`
|
| 17 |
-
|
| 18 |
-
```shell
|
| 19 |
-
python app.py --strategy "cuda fp16" --model_title "RWKV-x070-World-0.1B-v2.8-20241210-ctx4096" --download_repo_id "BlinkDL/rwkv-7-world" --download_model_dir ./
|
| 20 |
-
```
|
| 21 |
-
|
| 22 |
-
`RWKV7-G1-0.1B-68%trained-20250303-ctx4k`
|
| 23 |
-
|
| 24 |
-
```shell
|
| 25 |
-
python app.py --strategy "cuda fp16" --model_title "RWKV7-G1-0.1B-68%trained-20250303-ctx4k" --download_repo_id "BlinkDL/temp-latest-training-models" --download_model_dir ./
|
| 26 |
-
```
|
| 27 |
-
|
| 28 |
-
`RWKV7-G1-0.4B-68%trained-20250303-ctx4k`
|
| 29 |
-
|
| 30 |
-
```shell
|
| 31 |
-
python app.py --strategy "cuda fp16" --model_title "RWKV7-G1-0.4B-32%trained-20250304-ctx4k" --download_repo_id "BlinkDL/temp-latest-training-models" --download_model_dir ./
|
| 32 |
-
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
api_types.py
DELETED
|
@@ -1,82 +0,0 @@
|
|
| 1 |
-
from typing import List, Optional, Union, Dict, Any, Literal
|
| 2 |
-
from pydantic import BaseModel, Field
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
class ChatMessage(BaseModel):
|
| 6 |
-
role: str = Field()
|
| 7 |
-
content: str = Field()
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
class Logprob(BaseModel):
|
| 11 |
-
token: str
|
| 12 |
-
logprob: float
|
| 13 |
-
top_logprobs: Optional[List[Dict[str, Any]]] = None
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
class LogprobsContent(BaseModel):
|
| 17 |
-
content: Optional[List[Logprob]] = None
|
| 18 |
-
refusal: Optional[List[Logprob]] = None
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
class FunctionCall(BaseModel):
|
| 22 |
-
name: str
|
| 23 |
-
arguments: str
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
class ChatCompletionMessage(BaseModel):
|
| 27 |
-
role: Optional[str] = Field(
|
| 28 |
-
None, description="The role of the author of this message"
|
| 29 |
-
)
|
| 30 |
-
content: Optional[str] = Field(None, description="The contents of the message")
|
| 31 |
-
reasoning_content: Optional[str] = Field(
|
| 32 |
-
None, description="The reasoning contents of the message"
|
| 33 |
-
)
|
| 34 |
-
tool_calls: Optional[List[Dict[str, Any]]] = Field(
|
| 35 |
-
None, description="Tool calls generated by the model"
|
| 36 |
-
)
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
class PromptTokensDetails(BaseModel):
|
| 40 |
-
cached_tokens: int
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
class CompletionTokensDetails(BaseModel):
|
| 44 |
-
reasoning_tokens: int
|
| 45 |
-
accepted_prediction_tokens: int
|
| 46 |
-
rejected_prediction_tokens: int
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
class Usage(BaseModel):
|
| 50 |
-
prompt_tokens: int
|
| 51 |
-
completion_tokens: int
|
| 52 |
-
total_tokens: int
|
| 53 |
-
prompt_tokens_details: Optional[PromptTokensDetails]
|
| 54 |
-
# completion_tokens_details: CompletionTokensDetails
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
class ChatCompletionChoice(BaseModel):
|
| 58 |
-
index: int
|
| 59 |
-
message: Optional[ChatCompletionMessage] = None
|
| 60 |
-
delta: Optional[ChatCompletionMessage] = None
|
| 61 |
-
logprobs: Optional[LogprobsContent] = None
|
| 62 |
-
finish_reason: Optional[str] = Field(
|
| 63 |
-
..., description="Reason for stopping: stop, length, content_filter, tool_calls"
|
| 64 |
-
)
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
class ChatCompletion(BaseModel):
|
| 68 |
-
id: str = Field(..., description="Unique identifier for the chat completion")
|
| 69 |
-
object: Literal["chat.completion"] = "chat.completion"
|
| 70 |
-
created: int = Field(..., description="Unix timestamp of creation")
|
| 71 |
-
model: str
|
| 72 |
-
choices: List[ChatCompletionChoice]
|
| 73 |
-
usage: Usage
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
class ChatCompletionChunk(BaseModel):
|
| 77 |
-
id: str = Field(..., description="Unique identifier for the chat completion")
|
| 78 |
-
object: Literal["chat.completion.chunk"] = "chat.completion.chunk"
|
| 79 |
-
created: int = Field(..., description="Unix timestamp of creation")
|
| 80 |
-
model: str
|
| 81 |
-
choices: List[ChatCompletionChoice]
|
| 82 |
-
usage: Optional[Usage]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,717 +1,242 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
import
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
from
|
| 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 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
)
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
)
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
def
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
|
| 182 |
-
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
)
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
)
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
)
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
# out[0] -= 1e10 # disable END_OF_TEXT
|
| 244 |
-
|
| 245 |
-
token = MODEL_STORAGE[request.model].pipeline.sample_logits(
|
| 246 |
-
out, temperature=args.temperature, top_p=args.top_p
|
| 247 |
-
)
|
| 248 |
-
|
| 249 |
-
if token == 0 and token in request.stop_tokens:
|
| 250 |
-
yield {
|
| 251 |
-
"content": "".join(cache_word_list),
|
| 252 |
-
"tokens": out_tokens[out_last:],
|
| 253 |
-
"finish_reason": "stop:token:0",
|
| 254 |
-
"state": model_state,
|
| 255 |
-
}
|
| 256 |
-
|
| 257 |
-
del out
|
| 258 |
-
gc.collect()
|
| 259 |
-
return
|
| 260 |
-
|
| 261 |
-
out, model_state = MODEL_STORAGE[request.model].model.forward(
|
| 262 |
-
[token], model_state
|
| 263 |
-
)
|
| 264 |
-
|
| 265 |
-
model_tokens.append(token)
|
| 266 |
-
out_tokens.append(token)
|
| 267 |
-
|
| 268 |
-
if token in request.stop_tokens:
|
| 269 |
-
yield {
|
| 270 |
-
"content": "".join(cache_word_list),
|
| 271 |
-
"tokens": out_tokens[out_last:],
|
| 272 |
-
"finish_reason": f"stop:token:{token}",
|
| 273 |
-
"state": model_state,
|
| 274 |
-
}
|
| 275 |
-
|
| 276 |
-
del out
|
| 277 |
-
gc.collect()
|
| 278 |
-
return
|
| 279 |
-
|
| 280 |
-
for xxx in occurrence:
|
| 281 |
-
occurrence[xxx] *= request.penalty_decay
|
| 282 |
-
occurrence[token] = 1 + (occurrence[token] if token in occurrence else 0)
|
| 283 |
-
|
| 284 |
-
tmp: str = MODEL_STORAGE[request.model].pipeline.decode(out_tokens[out_last:])
|
| 285 |
-
|
| 286 |
-
if "\ufffd" in tmp:
|
| 287 |
-
continue
|
| 288 |
-
|
| 289 |
-
cache_word_list.append(tmp)
|
| 290 |
-
output_cache_str = "".join(cache_word_list)
|
| 291 |
-
|
| 292 |
-
for stop_words in request.stop:
|
| 293 |
-
if stop_words in output_cache_str:
|
| 294 |
-
yield {
|
| 295 |
-
"content": output_cache_str.replace(stop_words, ""),
|
| 296 |
-
"tokens": out_tokens[out_last - cache_word_len :],
|
| 297 |
-
"finish_reason": f"stop:words:{stop_words}",
|
| 298 |
-
"state": model_state,
|
| 299 |
-
}
|
| 300 |
-
|
| 301 |
-
del out
|
| 302 |
-
gc.collect()
|
| 303 |
-
return
|
| 304 |
-
|
| 305 |
-
if len(cache_word_list) > cache_word_len:
|
| 306 |
-
yield {
|
| 307 |
-
"content": cache_word_list.pop(0),
|
| 308 |
-
"tokens": out_tokens[out_last - cache_word_len :],
|
| 309 |
-
"finish_reason": None,
|
| 310 |
-
}
|
| 311 |
-
|
| 312 |
-
out_last = i + 1
|
| 313 |
-
|
| 314 |
-
else:
|
| 315 |
-
yield {
|
| 316 |
-
"content": "",
|
| 317 |
-
"tokens": [],
|
| 318 |
-
"finish_reason": "length",
|
| 319 |
-
}
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
async def chatResponse(
|
| 323 |
-
request: ChatCompletionRequest,
|
| 324 |
-
model_state: any,
|
| 325 |
-
completionId: str,
|
| 326 |
-
enableReasoning: bool,
|
| 327 |
-
) -> ChatCompletion:
|
| 328 |
-
createTimestamp = time.time()
|
| 329 |
-
|
| 330 |
-
prompt = (
|
| 331 |
-
f"{cleanMessages(request.messages)}\n\nAssistant:{' <think' if enableReasoning else ''}"
|
| 332 |
-
if request.prompt == None
|
| 333 |
-
else request.prompt.strip()
|
| 334 |
-
)
|
| 335 |
-
logger.info(f"[REQ] {completionId} - prompt - {prompt}")
|
| 336 |
-
|
| 337 |
-
out, model_tokens, model_state = await runPrefill(request, prompt, [0], model_state)
|
| 338 |
-
|
| 339 |
-
prefillTime = time.time()
|
| 340 |
-
promptTokenCount = len(model_tokens)
|
| 341 |
-
|
| 342 |
-
fullResponse = " <think" if enableReasoning else ""
|
| 343 |
-
completionTokenCount = 0
|
| 344 |
-
finishReason = None
|
| 345 |
-
|
| 346 |
-
for chunk in generate(
|
| 347 |
-
request,
|
| 348 |
-
out,
|
| 349 |
-
model_tokens,
|
| 350 |
-
model_state,
|
| 351 |
-
max_tokens=(
|
| 352 |
-
64000
|
| 353 |
-
if "max_tokens" not in request.model_fields_set and enableReasoning
|
| 354 |
-
else request.max_tokens
|
| 355 |
-
),
|
| 356 |
-
):
|
| 357 |
-
fullResponse += chunk["content"]
|
| 358 |
-
completionTokenCount += 1
|
| 359 |
-
|
| 360 |
-
if chunk["finish_reason"]:
|
| 361 |
-
finishReason = chunk["finish_reason"]
|
| 362 |
-
await asyncio.sleep(0)
|
| 363 |
-
|
| 364 |
-
genenrateTime = time.time()
|
| 365 |
-
|
| 366 |
-
responseLog = {
|
| 367 |
-
"content": fullResponse,
|
| 368 |
-
"finish": finishReason,
|
| 369 |
-
"prefill_len": promptTokenCount,
|
| 370 |
-
"prefill_tps": round(promptTokenCount / (prefillTime - createTimestamp), 2),
|
| 371 |
-
"gen_len": completionTokenCount,
|
| 372 |
-
"gen_tps": round(completionTokenCount / (genenrateTime - prefillTime), 2),
|
| 373 |
-
}
|
| 374 |
-
logger.info(f"[RES] {completionId} - {responseLog}")
|
| 375 |
-
|
| 376 |
-
reasoning_content, content = parse_think_response(fullResponse)
|
| 377 |
-
|
| 378 |
-
response = ChatCompletion(
|
| 379 |
-
id=completionId,
|
| 380 |
-
created=int(createTimestamp),
|
| 381 |
-
model=request.model,
|
| 382 |
-
usage=Usage(
|
| 383 |
-
prompt_tokens=promptTokenCount,
|
| 384 |
-
completion_tokens=completionTokenCount,
|
| 385 |
-
total_tokens=promptTokenCount + completionTokenCount,
|
| 386 |
-
prompt_tokens_details={"cached_tokens": 0},
|
| 387 |
-
),
|
| 388 |
-
choices=[
|
| 389 |
-
ChatCompletionChoice(
|
| 390 |
-
index=0,
|
| 391 |
-
message=ChatCompletionMessage(
|
| 392 |
-
role="Assistant",
|
| 393 |
-
content=content,
|
| 394 |
-
reasoning_content=reasoning_content if reasoning_content else None,
|
| 395 |
-
),
|
| 396 |
-
logprobs=None,
|
| 397 |
-
finish_reason=finishReason,
|
| 398 |
-
)
|
| 399 |
-
],
|
| 400 |
-
)
|
| 401 |
-
|
| 402 |
-
return response
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
async def chatResponseStream(
|
| 406 |
-
request: ChatCompletionRequest,
|
| 407 |
-
model_state: any,
|
| 408 |
-
completionId: str,
|
| 409 |
-
enableReasoning: bool,
|
| 410 |
-
):
|
| 411 |
-
createTimestamp = int(time.time())
|
| 412 |
-
|
| 413 |
-
prompt = (
|
| 414 |
-
f"{cleanMessages(request.messages,enableReasoning)}\n\nAssistant:{' <think' if enableReasoning else ''}"
|
| 415 |
-
if request.prompt == None
|
| 416 |
-
else request.prompt.strip()
|
| 417 |
-
)
|
| 418 |
-
|
| 419 |
-
logger.info(f"[REQ] {completionId} - context\n```{prompt}```")
|
| 420 |
-
|
| 421 |
-
out, model_tokens, model_state = await runPrefill(request, prompt, [0], model_state)
|
| 422 |
-
|
| 423 |
-
prefillTime = time.time()
|
| 424 |
-
promptTokenCount = len(model_tokens)
|
| 425 |
-
|
| 426 |
-
completionTokenCount = 0
|
| 427 |
-
finishReason = None
|
| 428 |
-
|
| 429 |
-
response = ChatCompletionChunk(
|
| 430 |
-
id=completionId,
|
| 431 |
-
created=createTimestamp,
|
| 432 |
-
model=request.model,
|
| 433 |
-
usage=(
|
| 434 |
-
Usage(
|
| 435 |
-
prompt_tokens=promptTokenCount,
|
| 436 |
-
completion_tokens=completionTokenCount,
|
| 437 |
-
total_tokens=promptTokenCount + completionTokenCount,
|
| 438 |
-
prompt_tokens_details={"cached_tokens": 0},
|
| 439 |
-
)
|
| 440 |
-
if request.include_usage
|
| 441 |
-
else None
|
| 442 |
-
),
|
| 443 |
-
choices=[
|
| 444 |
-
ChatCompletionChoice(
|
| 445 |
-
index=0,
|
| 446 |
-
delta=ChatCompletionMessage(
|
| 447 |
-
role="Assistant",
|
| 448 |
-
content="",
|
| 449 |
-
reasoning_content="" if enableReasoning else None,
|
| 450 |
-
),
|
| 451 |
-
logprobs=None,
|
| 452 |
-
finish_reason=finishReason,
|
| 453 |
-
)
|
| 454 |
-
],
|
| 455 |
-
)
|
| 456 |
-
yield f"data: {response.model_dump_json()}\n\n"
|
| 457 |
-
|
| 458 |
-
buffer = []
|
| 459 |
-
|
| 460 |
-
if enableReasoning:
|
| 461 |
-
buffer.append("<think")
|
| 462 |
-
|
| 463 |
-
streamConfig = {
|
| 464 |
-
"isChecking": False, # check whether is <think> tag
|
| 465 |
-
"fullTextCursor": 0,
|
| 466 |
-
"in_think": False,
|
| 467 |
-
"cacheStr": "",
|
| 468 |
-
}
|
| 469 |
-
|
| 470 |
-
for chunk in generate(
|
| 471 |
-
request,
|
| 472 |
-
out,
|
| 473 |
-
model_tokens,
|
| 474 |
-
model_state,
|
| 475 |
-
max_tokens=(
|
| 476 |
-
64000
|
| 477 |
-
if "max_tokens" not in request.model_fields_set and enableReasoning
|
| 478 |
-
else request.max_tokens
|
| 479 |
-
),
|
| 480 |
-
):
|
| 481 |
-
completionTokenCount += 1
|
| 482 |
-
|
| 483 |
-
chunkContent: str = chunk["content"]
|
| 484 |
-
buffer.append(chunkContent)
|
| 485 |
-
|
| 486 |
-
fullText = "".join(buffer)
|
| 487 |
-
|
| 488 |
-
if chunk["finish_reason"]:
|
| 489 |
-
finishReason = chunk["finish_reason"]
|
| 490 |
-
|
| 491 |
-
response = ChatCompletionChunk(
|
| 492 |
-
id=completionId,
|
| 493 |
-
created=createTimestamp,
|
| 494 |
-
model=request.model,
|
| 495 |
-
usage=(
|
| 496 |
-
Usage(
|
| 497 |
-
prompt_tokens=promptTokenCount,
|
| 498 |
-
completion_tokens=completionTokenCount,
|
| 499 |
-
total_tokens=promptTokenCount + completionTokenCount,
|
| 500 |
-
prompt_tokens_details={"cached_tokens": 0},
|
| 501 |
-
)
|
| 502 |
-
if request.include_usage
|
| 503 |
-
else None
|
| 504 |
-
),
|
| 505 |
-
choices=[
|
| 506 |
-
ChatCompletionChoice(
|
| 507 |
-
index=0,
|
| 508 |
-
delta=ChatCompletionMessage(
|
| 509 |
-
content=None, reasoning_content=None
|
| 510 |
-
),
|
| 511 |
-
logprobs=None,
|
| 512 |
-
finish_reason=finishReason,
|
| 513 |
-
)
|
| 514 |
-
],
|
| 515 |
-
)
|
| 516 |
-
|
| 517 |
-
markStart = fullText.find("<", streamConfig["fullTextCursor"])
|
| 518 |
-
if not streamConfig["isChecking"] and markStart != -1:
|
| 519 |
-
streamConfig["isChecking"] = True
|
| 520 |
-
|
| 521 |
-
if streamConfig["in_think"]:
|
| 522 |
-
response.choices[0].delta.reasoning_content = fullText[
|
| 523 |
-
streamConfig["fullTextCursor"] : markStart
|
| 524 |
-
]
|
| 525 |
-
else:
|
| 526 |
-
response.choices[0].delta.content = fullText[
|
| 527 |
-
streamConfig["fullTextCursor"] : markStart
|
| 528 |
-
]
|
| 529 |
-
|
| 530 |
-
streamConfig["cacheStr"] = ""
|
| 531 |
-
streamConfig["fullTextCursor"] = markStart
|
| 532 |
-
|
| 533 |
-
if streamConfig["isChecking"]:
|
| 534 |
-
streamConfig["cacheStr"] = fullText[streamConfig["fullTextCursor"] :]
|
| 535 |
-
else:
|
| 536 |
-
if streamConfig["in_think"]:
|
| 537 |
-
response.choices[0].delta.reasoning_content = chunkContent
|
| 538 |
-
else:
|
| 539 |
-
response.choices[0].delta.content = chunkContent
|
| 540 |
-
streamConfig["fullTextCursor"] = len(fullText)
|
| 541 |
-
|
| 542 |
-
markEnd = fullText.find(">", streamConfig["fullTextCursor"])
|
| 543 |
-
if (streamConfig["isChecking"] and markEnd != -1) or finishReason != None:
|
| 544 |
-
streamConfig["isChecking"] = False
|
| 545 |
-
|
| 546 |
-
if (
|
| 547 |
-
not streamConfig["in_think"]
|
| 548 |
-
and streamConfig["cacheStr"].find("<think>") != -1
|
| 549 |
-
):
|
| 550 |
-
streamConfig["in_think"] = True
|
| 551 |
-
|
| 552 |
-
response.choices[0].delta.reasoning_content = (
|
| 553 |
-
response.choices[0].delta.reasoning_content
|
| 554 |
-
if response.choices[0].delta.reasoning_content != None
|
| 555 |
-
else "" + streamConfig["cacheStr"].replace("<think>", "")
|
| 556 |
-
)
|
| 557 |
-
|
| 558 |
-
elif (
|
| 559 |
-
streamConfig["in_think"]
|
| 560 |
-
and streamConfig["cacheStr"].find("</think>") != -1
|
| 561 |
-
):
|
| 562 |
-
streamConfig["in_think"] = False
|
| 563 |
-
|
| 564 |
-
response.choices[0].delta.content = (
|
| 565 |
-
response.choices[0].delta.content
|
| 566 |
-
if response.choices[0].delta.content != None
|
| 567 |
-
else "" + streamConfig["cacheStr"].replace("</think>", "")
|
| 568 |
-
)
|
| 569 |
-
else:
|
| 570 |
-
if streamConfig["in_think"]:
|
| 571 |
-
response.choices[0].delta.reasoning_content = (
|
| 572 |
-
response.choices[0].delta.reasoning_content
|
| 573 |
-
if response.choices[0].delta.reasoning_content != None
|
| 574 |
-
else "" + streamConfig["cacheStr"]
|
| 575 |
-
)
|
| 576 |
-
else:
|
| 577 |
-
response.choices[0].delta.content = (
|
| 578 |
-
response.choices[0].delta.content
|
| 579 |
-
if response.choices[0].delta.content != None
|
| 580 |
-
else "" + streamConfig["cacheStr"]
|
| 581 |
-
)
|
| 582 |
-
streamConfig["fullTextCursor"] = len(fullText)
|
| 583 |
-
|
| 584 |
-
if (
|
| 585 |
-
response.choices[0].delta.content != None
|
| 586 |
-
or response.choices[0].delta.reasoning_content != None
|
| 587 |
-
):
|
| 588 |
-
yield f"data: {response.model_dump_json()}\n\n"
|
| 589 |
-
|
| 590 |
-
await asyncio.sleep(0)
|
| 591 |
-
|
| 592 |
-
del streamConfig
|
| 593 |
-
else:
|
| 594 |
-
for chunk in generate(request, out, model_tokens, model_state):
|
| 595 |
-
completionTokenCount += 1
|
| 596 |
-
buffer.append(chunk["content"])
|
| 597 |
-
|
| 598 |
-
if chunk["finish_reason"]:
|
| 599 |
-
finishReason = chunk["finish_reason"]
|
| 600 |
-
|
| 601 |
-
response = ChatCompletionChunk(
|
| 602 |
-
id=completionId,
|
| 603 |
-
created=createTimestamp,
|
| 604 |
-
model=request.model,
|
| 605 |
-
usage=(
|
| 606 |
-
Usage(
|
| 607 |
-
prompt_tokens=promptTokenCount,
|
| 608 |
-
completion_tokens=completionTokenCount,
|
| 609 |
-
total_tokens=promptTokenCount + completionTokenCount,
|
| 610 |
-
prompt_tokens_details={"cached_tokens": 0},
|
| 611 |
-
)
|
| 612 |
-
if request.include_usage
|
| 613 |
-
else None
|
| 614 |
-
),
|
| 615 |
-
choices=[
|
| 616 |
-
ChatCompletionChoice(
|
| 617 |
-
index=0,
|
| 618 |
-
delta=ChatCompletionMessage(content=chunk["content"]),
|
| 619 |
-
logprobs=None,
|
| 620 |
-
finish_reason=finishReason,
|
| 621 |
-
)
|
| 622 |
-
],
|
| 623 |
-
)
|
| 624 |
-
|
| 625 |
-
yield f"data: {response.model_dump_json()}\n\n"
|
| 626 |
-
await asyncio.sleep(0)
|
| 627 |
-
|
| 628 |
-
genenrateTime = time.time()
|
| 629 |
-
|
| 630 |
-
responseLog = {
|
| 631 |
-
"content": "".join(buffer),
|
| 632 |
-
"finish": finishReason,
|
| 633 |
-
"prefill_len": promptTokenCount,
|
| 634 |
-
"prefill_tps": round(promptTokenCount / (prefillTime - createTimestamp), 2),
|
| 635 |
-
"gen_len": completionTokenCount,
|
| 636 |
-
"gen_tps": round(completionTokenCount / (genenrateTime - prefillTime), 2),
|
| 637 |
-
}
|
| 638 |
-
logger.info(f"[RES] {completionId} - {responseLog}")
|
| 639 |
-
request.messages.append(
|
| 640 |
-
ChatMessage(role="Assistant", content=responseLog["content"])
|
| 641 |
-
)
|
| 642 |
-
log(
|
| 643 |
-
{
|
| 644 |
-
**request.model_dump(),
|
| 645 |
-
**responseLog,
|
| 646 |
-
"completionId": completionId,
|
| 647 |
-
"machineLabel": os.environ.get("MACHINE_LABEL"),
|
| 648 |
-
}
|
| 649 |
-
)
|
| 650 |
-
|
| 651 |
-
del buffer
|
| 652 |
-
|
| 653 |
-
yield "data: [DONE]\n\n"
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
@app.post("/api/v1/chat/completions")
|
| 657 |
-
async def chat_completions(request: ChatCompletionRequest):
|
| 658 |
-
completionId = str(next(CompletionIdGenerator))
|
| 659 |
-
logger.info(f"[REQ] {completionId} - {request.model_dump()}")
|
| 660 |
-
|
| 661 |
-
modelName = request.model.split(":")[0]
|
| 662 |
-
enableReasoning = ":thinking" in request.model
|
| 663 |
-
|
| 664 |
-
if "rwkv-latest" in request.model:
|
| 665 |
-
if enableReasoning:
|
| 666 |
-
if DEFAULT_REASONING_MODEL_NAME == None:
|
| 667 |
-
raise HTTPException(404, "DEFAULT_REASONING_MODEL_NAME not set")
|
| 668 |
-
defaultSamplerConfig = MODEL_STORAGE[
|
| 669 |
-
DEFAULT_REASONING_MODEL_NAME
|
| 670 |
-
].MODEL_CONFIG.DEFAULT_SAMPLER
|
| 671 |
-
request.model = DEFAULT_REASONING_MODEL_NAME
|
| 672 |
-
|
| 673 |
-
else:
|
| 674 |
-
if DEFALUT_MODEL_NAME == None:
|
| 675 |
-
raise HTTPException(404, "DEFALUT_MODEL_NAME not set")
|
| 676 |
-
defaultSamplerConfig = MODEL_STORAGE[
|
| 677 |
-
DEFALUT_MODEL_NAME
|
| 678 |
-
].MODEL_CONFIG.DEFAULT_SAMPLER
|
| 679 |
-
request.model = DEFALUT_MODEL_NAME
|
| 680 |
-
|
| 681 |
-
elif modelName in MODEL_STORAGE:
|
| 682 |
-
defaultSamplerConfig = MODEL_STORAGE[modelName].MODEL_CONFIG.DEFAULT_SAMPLER
|
| 683 |
-
request.model = modelName
|
| 684 |
-
else:
|
| 685 |
-
raise f"Can not find `{modelName}`"
|
| 686 |
-
|
| 687 |
-
async def chatResponseStreamDisconnect():
|
| 688 |
-
logGPUState()
|
| 689 |
-
|
| 690 |
-
model_state = None
|
| 691 |
-
request_dict = request.model_dump()
|
| 692 |
-
|
| 693 |
-
for k, v in defaultSamplerConfig.model_dump().items():
|
| 694 |
-
if request_dict[k] == None:
|
| 695 |
-
request_dict[k] = v
|
| 696 |
-
realRequest = ChatCompletionRequest(**request_dict)
|
| 697 |
-
|
| 698 |
-
logger.info(f"[REQ] {completionId} - Real - {request.model_dump()}")
|
| 699 |
-
|
| 700 |
-
if request.stream:
|
| 701 |
-
r = StreamingResponse(
|
| 702 |
-
chatResponseStream(realRequest, model_state, completionId, enableReasoning),
|
| 703 |
-
media_type="text/event-stream",
|
| 704 |
-
background=chatResponseStreamDisconnect,
|
| 705 |
-
)
|
| 706 |
-
else:
|
| 707 |
-
r = await chatResponse(realRequest, model_state, completionId, enableReasoning)
|
| 708 |
-
|
| 709 |
-
return r
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
app.mount("/", StaticFiles(directory="dist-frontend", html=True), name="static")
|
| 713 |
-
|
| 714 |
-
if __name__ == "__main__":
|
| 715 |
-
import uvicorn
|
| 716 |
-
|
| 717 |
-
uvicorn.run(app, host=CONFIG.HOST, port=CONFIG.PORT)
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
"""Hugging Face Space launcher for RWKV Lightning CUDA and the bundled UI.
|
| 3 |
+
|
| 4 |
+
The process exposed by a Space listens on port 7860. RWKV Lightning listens
|
| 5 |
+
locally on port 8000, so this script serves ``dist`` and proxies ``/v1`` to it.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import argparse
|
| 11 |
+
import contextlib
|
| 12 |
+
import http.client
|
| 13 |
+
import os
|
| 14 |
+
import shutil
|
| 15 |
+
import signal
|
| 16 |
+
import stat
|
| 17 |
+
import subprocess
|
| 18 |
+
import sys
|
| 19 |
+
import threading
|
| 20 |
+
import time
|
| 21 |
+
import urllib.error
|
| 22 |
+
import urllib.request
|
| 23 |
+
import zipfile
|
| 24 |
+
from http.server import SimpleHTTPRequestHandler, ThreadingHTTPServer
|
| 25 |
+
from pathlib import Path
|
| 26 |
+
from typing import BinaryIO
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
ROOT = Path(__file__).resolve().parent
|
| 30 |
+
DIST_DIR = ROOT / "dist"
|
| 31 |
+
MODELS_DIR = ROOT / "model_weights"
|
| 32 |
+
BACKEND_ARCHIVE = ROOT / "RWKV_lightning_CUDA.zip"
|
| 33 |
+
BACKEND_URL = (
|
| 34 |
+
"https://github.com/Alic-Li/rwkv_lightning_cuda/releases/download/V1.1.1/"
|
| 35 |
+
"RWKV_lightning_CUDA_sm75+_Linux_GCC15_V1.1.1.zip"
|
| 36 |
+
)
|
| 37 |
+
MODELS = {
|
| 38 |
+
"rwkv7-g1i-1.5b-20260805-ctx16384.pth": (
|
| 39 |
+
"https://huggingface.co/BlinkDL/rwkv7-g1/resolve/main/"
|
| 40 |
+
"rwkv7-g1i-1.5b-20260805-ctx16384.pth"
|
| 41 |
+
),
|
| 42 |
+
"rwkv7-g1i-2.9b-20260805-ctx16384.pth": (
|
| 43 |
+
"https://huggingface.co/BlinkDL/rwkv7-g1/resolve/main/"
|
| 44 |
+
"rwkv7-g1i-2.9b-20260805-ctx16384.pth"
|
| 45 |
+
),
|
| 46 |
+
"rwkv7-g1i-7.2b-20260805-ctx16384.pth": (
|
| 47 |
+
"https://huggingface.co/BlinkDL/rwkv7-g1/resolve/main/"
|
| 48 |
+
"rwkv7-g1i-7.2b-20260805-ctx16384.pth"
|
| 49 |
+
),
|
| 50 |
+
}
|
| 51 |
+
VOCAB_NAME = "rwkv_vocab_v20230424.txt"
|
| 52 |
+
BACKEND_PORT = 8000
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def download(url: str, destination: Path) -> None:
|
| 56 |
+
"""Download *url* atomically, continuing an interrupted .part download."""
|
| 57 |
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
| 58 |
+
partial = destination.with_name(destination.name + ".part")
|
| 59 |
+
offset = partial.stat().st_size if partial.exists() else 0
|
| 60 |
+
headers = {"User-Agent": "rwkv-hf-space-launcher/1.0"}
|
| 61 |
+
if offset:
|
| 62 |
+
headers["Range"] = f"bytes={offset}-"
|
| 63 |
+
request = urllib.request.Request(url, headers=headers)
|
| 64 |
+
print(f"Downloading {destination.name}" + (f" (resuming at {offset:,} bytes)" if offset else ""), flush=True)
|
| 65 |
+
try:
|
| 66 |
+
with urllib.request.urlopen(request, timeout=60) as response:
|
| 67 |
+
# Servers that ignore Range return the full file; do not append it.
|
| 68 |
+
mode = "ab" if offset and response.status == 206 else "wb"
|
| 69 |
+
with partial.open(mode) as output:
|
| 70 |
+
shutil.copyfileobj(response, output, length=8 * 1024 * 1024)
|
| 71 |
+
except urllib.error.URLError as exc:
|
| 72 |
+
raise RuntimeError(f"Could not download {url}: {exc}") from exc
|
| 73 |
+
partial.replace(destination)
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def safe_extract(archive: Path, destination: Path) -> None:
|
| 77 |
+
"""Extract a zip while rejecting entries that escape the project folder."""
|
| 78 |
+
with zipfile.ZipFile(archive) as zipped:
|
| 79 |
+
root = destination.resolve()
|
| 80 |
+
for member in zipped.infolist():
|
| 81 |
+
target = (destination / member.filename).resolve()
|
| 82 |
+
if target != root and root not in target.parents:
|
| 83 |
+
raise RuntimeError(f"Unsafe path in backend archive: {member.filename}")
|
| 84 |
+
zipped.extractall(destination)
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
def find_file(name: str) -> Path | None:
|
| 88 |
+
direct = ROOT / name
|
| 89 |
+
if direct.is_file():
|
| 90 |
+
return direct
|
| 91 |
+
return next((path for path in ROOT.rglob(name) if path.is_file()), None)
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def prepare_frontend() -> None:
|
| 95 |
+
if not (DIST_DIR / "index.html").is_file():
|
| 96 |
+
raise RuntimeError(f"Compiled frontend not found at {DIST_DIR}")
|
| 97 |
+
# The build was made for a local backend. In a Space, use this server's
|
| 98 |
+
# same-origin proxy so visitors do not try to contact their own computer.
|
| 99 |
+
for asset in DIST_DIR.rglob("*.js"):
|
| 100 |
+
content = asset.read_text(encoding="utf-8")
|
| 101 |
+
updated = content.replace("http://127.0.0.1:8000/v1", "/v1")
|
| 102 |
+
if updated != content:
|
| 103 |
+
asset.write_text(updated, encoding="utf-8")
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def prepare_backend() -> tuple[Path, Path]:
|
| 107 |
+
executable = find_file("rwkv_lighting_cuda") or find_file("rwkv_lightning_cuda")
|
| 108 |
+
if executable is None:
|
| 109 |
+
if not BACKEND_ARCHIVE.is_file():
|
| 110 |
+
download(BACKEND_URL, BACKEND_ARCHIVE)
|
| 111 |
+
print("Extracting RWKV Lightning CUDA backend", flush=True)
|
| 112 |
+
safe_extract(BACKEND_ARCHIVE, ROOT)
|
| 113 |
+
executable = find_file("rwkv_lighting_cuda") or find_file("rwkv_lightning_cuda")
|
| 114 |
+
if executable is None:
|
| 115 |
+
raise RuntimeError("Backend archive did not contain rwkv_lighting_cuda")
|
| 116 |
+
executable.chmod(executable.stat().st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
| 117 |
+
|
| 118 |
+
vocab = find_file(VOCAB_NAME)
|
| 119 |
+
if vocab is None:
|
| 120 |
+
raise RuntimeError(
|
| 121 |
+
f"Backend archive did not contain {VOCAB_NAME}; it is required by RWKV Lightning"
|
| 122 |
+
)
|
| 123 |
+
return executable, vocab
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def prepare_models() -> None:
|
| 127 |
+
for filename, url in MODELS.items():
|
| 128 |
+
destination = MODELS_DIR / filename
|
| 129 |
+
if destination.is_file() and destination.stat().st_size > 0:
|
| 130 |
+
print(f"Using existing model: {filename}", flush=True)
|
| 131 |
+
continue
|
| 132 |
+
download(url, destination)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
class SpaceHandler(SimpleHTTPRequestHandler):
|
| 136 |
+
"""Static frontend handler with a streaming reverse proxy for the API."""
|
| 137 |
+
|
| 138 |
+
protocol_version = "HTTP/1.1"
|
| 139 |
+
|
| 140 |
+
def __init__(self, *args: object, **kwargs: object) -> None:
|
| 141 |
+
# Never expose files beside the pre-built frontend (models, launcher,
|
| 142 |
+
# and downloaded archives must not be web-accessible).
|
| 143 |
+
super().__init__(*args, directory=str(DIST_DIR), **kwargs)
|
| 144 |
+
|
| 145 |
+
def do_GET(self) -> None:
|
| 146 |
+
self._dispatch()
|
| 147 |
+
|
| 148 |
+
def do_POST(self) -> None:
|
| 149 |
+
self._dispatch()
|
| 150 |
+
|
| 151 |
+
def do_OPTIONS(self) -> None:
|
| 152 |
+
self._dispatch()
|
| 153 |
+
|
| 154 |
+
def do_PUT(self) -> None:
|
| 155 |
+
self._dispatch()
|
| 156 |
+
|
| 157 |
+
def do_DELETE(self) -> None:
|
| 158 |
+
self._dispatch()
|
| 159 |
+
|
| 160 |
+
def _dispatch(self) -> None:
|
| 161 |
+
if self.path == "/v1" or self.path.startswith("/v1/"):
|
| 162 |
+
self._proxy()
|
| 163 |
+
else:
|
| 164 |
+
self._static_or_spa()
|
| 165 |
+
|
| 166 |
+
def _static_or_spa(self) -> None:
|
| 167 |
+
requested = self.path.split("?", 1)[0].split("#", 1)[0]
|
| 168 |
+
if requested != "/" and not (DIST_DIR / requested.lstrip("/")).is_file():
|
| 169 |
+
self.path = "/index.html"
|
| 170 |
+
super().do_GET()
|
| 171 |
+
|
| 172 |
+
def _proxy(self) -> None:
|
| 173 |
+
length = int(self.headers.get("Content-Length", "0"))
|
| 174 |
+
body: BinaryIO | bytes = self.rfile.read(length) if length else b""
|
| 175 |
+
forwarded_headers = {
|
| 176 |
+
key: value
|
| 177 |
+
for key, value in self.headers.items()
|
| 178 |
+
if key.lower() not in {"host", "connection", "content-length"}
|
| 179 |
+
}
|
| 180 |
+
try:
|
| 181 |
+
connection = http.client.HTTPConnection("127.0.0.1", BACKEND_PORT, timeout=600)
|
| 182 |
+
connection.request(self.command, self.path, body=body, headers=forwarded_headers)
|
| 183 |
+
response = connection.getresponse()
|
| 184 |
+
self.send_response(response.status, response.reason)
|
| 185 |
+
for key, value in response.getheaders():
|
| 186 |
+
if key.lower() not in {"connection", "transfer-encoding", "keep-alive"}:
|
| 187 |
+
self.send_header(key, value)
|
| 188 |
+
self.send_header("Connection", "close")
|
| 189 |
+
self.end_headers()
|
| 190 |
+
while chunk := response.read(64 * 1024):
|
| 191 |
+
self.wfile.write(chunk)
|
| 192 |
+
self.wfile.flush()
|
| 193 |
+
except (ConnectionError, OSError, http.client.HTTPException) as exc:
|
| 194 |
+
self.send_error(503, f"RWKV backend is starting or unavailable: {exc}")
|
| 195 |
+
finally:
|
| 196 |
+
with contextlib.suppress(UnboundLocalError):
|
| 197 |
+
connection.close()
|
| 198 |
+
|
| 199 |
+
def log_message(self, format: str, *args: object) -> None:
|
| 200 |
+
print(f"[web] {self.address_string()} - {format % args}", flush=True)
|
| 201 |
+
|
| 202 |
+
|
| 203 |
+
def run(host: str, port: int) -> None:
|
| 204 |
+
prepare_frontend()
|
| 205 |
+
executable, vocab = prepare_backend()
|
| 206 |
+
prepare_models()
|
| 207 |
+
|
| 208 |
+
command = [
|
| 209 |
+
str(executable),
|
| 210 |
+
"--enable-dynamic-loading",
|
| 211 |
+
"--model-path",
|
| 212 |
+
str(MODELS_DIR),
|
| 213 |
+
"--vocab-path",
|
| 214 |
+
str(vocab),
|
| 215 |
+
]
|
| 216 |
+
print("Starting backend:", " ".join(command), flush=True)
|
| 217 |
+
backend = subprocess.Popen(command, cwd=executable.parent, env=os.environ.copy())
|
| 218 |
+
|
| 219 |
+
def stop_backend(*_: object) -> None:
|
| 220 |
+
if backend.poll() is None:
|
| 221 |
+
backend.terminate()
|
| 222 |
+
|
| 223 |
+
signal.signal(signal.SIGTERM, stop_backend)
|
| 224 |
+
signal.signal(signal.SIGINT, stop_backend)
|
| 225 |
+
server = ThreadingHTTPServer((host, port), SpaceHandler)
|
| 226 |
+
server.daemon_threads = True
|
| 227 |
+
print(f"Serving frontend on http://{host}:{port}", flush=True)
|
| 228 |
+
try:
|
| 229 |
+
server.serve_forever()
|
| 230 |
+
finally:
|
| 231 |
+
server.server_close()
|
| 232 |
+
stop_backend()
|
| 233 |
+
with contextlib.suppress(subprocess.TimeoutExpired):
|
| 234 |
+
backend.wait(timeout=10)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
if __name__ == "__main__":
|
| 238 |
+
parser = argparse.ArgumentParser(description="Run the RWKV CUDA Hugging Face Space")
|
| 239 |
+
parser.add_argument("--host", default="0.0.0.0")
|
| 240 |
+
parser.add_argument("--port", type=int, default=int(os.environ.get("PORT", "7860")))
|
| 241 |
+
args = parser.parse_args()
|
| 242 |
+
run(args.host, args.port)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.production-modelscope.yaml
DELETED
|
@@ -1,68 +0,0 @@
|
|
| 1 |
-
HOST: "0.0.0.0"
|
| 2 |
-
PORT: 7860
|
| 3 |
-
STRATEGY: "cuda fp16"
|
| 4 |
-
RWKV_CUDA_ON: True
|
| 5 |
-
CHUNK_LEN: 256
|
| 6 |
-
MODELS:
|
| 7 |
-
- SERVICE_NAME: "rwkv7-g1c-2.9b-20251231-ctx8192"
|
| 8 |
-
DOWNLOAD_MODEL_FILE_NAME: "rwkv7-g1c-2.9b-20251231-ctx8192.pth"
|
| 9 |
-
DOWNLOAD_MODEL_REPO_ID: "RWKV/rwkv7-g1"
|
| 10 |
-
REASONING: True
|
| 11 |
-
DEFAULT_SAMPLER:
|
| 12 |
-
max_tokens: 8192
|
| 13 |
-
temperature: 1.0
|
| 14 |
-
top_p: 0.3
|
| 15 |
-
presence_penalty: 0.5
|
| 16 |
-
count_penalty: 0.5
|
| 17 |
-
penalty_decay: 0.996
|
| 18 |
-
stop:
|
| 19 |
-
- "\n\n"
|
| 20 |
-
stop_tokens:
|
| 21 |
-
- 0
|
| 22 |
-
- SERVICE_NAME: "rwkv7-g1b-1.5b-20251202-ctx8192"
|
| 23 |
-
DOWNLOAD_MODEL_FILE_NAME: "rwkv7-g1b-1.5b-20251202-ctx8192.pth"
|
| 24 |
-
DOWNLOAD_MODEL_REPO_ID: "RWKV/rwkv7-g1"
|
| 25 |
-
REASONING: True
|
| 26 |
-
DEFAULT_SAMPLER:
|
| 27 |
-
max_tokens: 8192
|
| 28 |
-
temperature: 1.0
|
| 29 |
-
top_p: 0.3
|
| 30 |
-
presence_penalty: 0.5
|
| 31 |
-
count_penalty: 0.5
|
| 32 |
-
penalty_decay: 0.996
|
| 33 |
-
stop:
|
| 34 |
-
- "\n\n"
|
| 35 |
-
stop_tokens:
|
| 36 |
-
- 0
|
| 37 |
-
- SERVICE_NAME: "rwkv7-g1a-0.4b-20250905-ctx4096"
|
| 38 |
-
DOWNLOAD_MODEL_FILE_NAME: "rwkv7-g1a-0.4b-20250905-ctx4096.pth"
|
| 39 |
-
DOWNLOAD_MODEL_REPO_ID: "RWKV/rwkv7-g1"
|
| 40 |
-
REASONING: True
|
| 41 |
-
DEFAULT_SAMPLER:
|
| 42 |
-
max_tokens: 4096
|
| 43 |
-
temperature: 1.0
|
| 44 |
-
top_p: 0.3
|
| 45 |
-
presence_penalty: 0.5
|
| 46 |
-
count_penalty: 0.5
|
| 47 |
-
penalty_decay: 0.996
|
| 48 |
-
stop:
|
| 49 |
-
- "\n\n"
|
| 50 |
-
stop_tokens:
|
| 51 |
-
- 0
|
| 52 |
-
- SERVICE_NAME: "rwkv7-g1a-0.1b-20250728-ctx4096"
|
| 53 |
-
DOWNLOAD_MODEL_FILE_NAME: "rwkv7-g1a-0.1b-20250728-ctx4096.pth"
|
| 54 |
-
DOWNLOAD_MODEL_REPO_ID: "RWKV/rwkv7-g1"
|
| 55 |
-
REASONING: True
|
| 56 |
-
DEFAULT_CHAT: True
|
| 57 |
-
DEFAULT_REASONING: True
|
| 58 |
-
DEFAULT_SAMPLER:
|
| 59 |
-
max_tokens: 4096
|
| 60 |
-
temperature: 1.0
|
| 61 |
-
top_p: 0.3
|
| 62 |
-
presence_penalty: 0.5
|
| 63 |
-
count_penalty: 0.5
|
| 64 |
-
penalty_decay: 0.996
|
| 65 |
-
stop:
|
| 66 |
-
- "\n\n"
|
| 67 |
-
stop_tokens:
|
| 68 |
-
- 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.production.yaml
DELETED
|
@@ -1,73 +0,0 @@
|
|
| 1 |
-
HOST: "0.0.0.0"
|
| 2 |
-
PORT: 7860
|
| 3 |
-
STRATEGY: "cuda fp16"
|
| 4 |
-
RWKV_CUDA_ON: True
|
| 5 |
-
CHUNK_LEN: 256
|
| 6 |
-
|
| 7 |
-
MODELS:
|
| 8 |
-
- SERVICE_NAME: "rwkv7-g1i-2.9b-20260805-ctx16384"
|
| 9 |
-
DOWNLOAD_MODEL_FILE_NAME: "rwkv7-g1i-2.9b-20260805-ctx16384.pth"
|
| 10 |
-
DOWNLOAD_MODEL_REPO_ID: "BlinkDL/rwkv7-g1"
|
| 11 |
-
REASONING: True
|
| 12 |
-
DEFAULT_CHAT: True
|
| 13 |
-
DEFAULT_REASONING: True
|
| 14 |
-
DEFAULT_SAMPLER:
|
| 15 |
-
max_tokens: 8192
|
| 16 |
-
temperature: 1.0
|
| 17 |
-
top_p: 0.5
|
| 18 |
-
presence_penalty: 2.0
|
| 19 |
-
count_penalty: 0.1
|
| 20 |
-
penalty_decay: 0.99
|
| 21 |
-
stop:
|
| 22 |
-
- "\n\n"
|
| 23 |
-
stop_tokens:
|
| 24 |
-
- 0
|
| 25 |
-
|
| 26 |
-
- SERVICE_NAME: "rwkv7-g1i-1.5b-20260805-ctx16384"
|
| 27 |
-
DOWNLOAD_MODEL_FILE_NAME: "rwkv7-g1i-1.5b-20260805-ctx16384.pth"
|
| 28 |
-
DOWNLOAD_MODEL_REPO_ID: "BlinkDL/rwkv7-g1"
|
| 29 |
-
REASONING: True
|
| 30 |
-
DEFAULT_SAMPLER:
|
| 31 |
-
max_tokens: 8192
|
| 32 |
-
temperature: 1.0
|
| 33 |
-
top_p: 0.5
|
| 34 |
-
presence_penalty: 2.0
|
| 35 |
-
count_penalty: 0.1
|
| 36 |
-
penalty_decay: 0.99
|
| 37 |
-
stop:
|
| 38 |
-
- "\n\n"
|
| 39 |
-
stop_tokens:
|
| 40 |
-
- 0
|
| 41 |
-
|
| 42 |
-
- SERVICE_NAME: "rwkv7-g1d-0.4b-20260210-ctx8192"
|
| 43 |
-
DOWNLOAD_MODEL_FILE_NAME: "rwkv7-g1d-0.4b-20260210-ctx8192.pth"
|
| 44 |
-
DOWNLOAD_MODEL_REPO_ID: "BlinkDL/rwkv7-g1"
|
| 45 |
-
REASONING: True
|
| 46 |
-
DEFAULT_SAMPLER:
|
| 47 |
-
max_tokens: 8192
|
| 48 |
-
temperature: 1.0
|
| 49 |
-
top_p: 0.3
|
| 50 |
-
presence_penalty: 0.5
|
| 51 |
-
count_penalty: 0.5
|
| 52 |
-
penalty_decay: 0.996
|
| 53 |
-
stop:
|
| 54 |
-
- "\n\n"
|
| 55 |
-
stop_tokens:
|
| 56 |
-
- 0
|
| 57 |
-
- SERVICE_NAME: "rwkv7-g1d-0.1b-20260129-ctx8192"
|
| 58 |
-
DOWNLOAD_MODEL_FILE_NAME: "rwkv7-g1d-0.1b-20260129-ctx8192.pth"
|
| 59 |
-
DOWNLOAD_MODEL_REPO_ID: "BlinkDL/rwkv7-g1"
|
| 60 |
-
REASONING: True
|
| 61 |
-
DEFAULT_CHAT: True
|
| 62 |
-
DEFAULT_REASONING: True
|
| 63 |
-
DEFAULT_SAMPLER:
|
| 64 |
-
max_tokens: 4096
|
| 65 |
-
temperature: 1.0
|
| 66 |
-
top_p: 0.3
|
| 67 |
-
presence_penalty: 0.5
|
| 68 |
-
count_penalty: 0.5
|
| 69 |
-
penalty_decay: 0.996
|
| 70 |
-
stop:
|
| 71 |
-
- "\n\n"
|
| 72 |
-
stop_tokens:
|
| 73 |
-
- 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.py
DELETED
|
@@ -1,84 +0,0 @@
|
|
| 1 |
-
from pydantic import BaseModel, Field
|
| 2 |
-
from typing import List, Optional
|
| 3 |
-
from typing import List, Optional, Union, Any
|
| 4 |
-
|
| 5 |
-
import sys
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
from pydantic_settings import BaseSettings
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
class CliConfig(BaseSettings, cli_parse_args=True, cli_use_class_docs_for_groups=True):
|
| 12 |
-
CONFIG_FILE: str = Field("./config.local.yaml", description="Config file path")
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
CLI_CONFIG = CliConfig()
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
class SamplerConfig(BaseModel):
|
| 19 |
-
"""Default sampler configuration for each model."""
|
| 20 |
-
|
| 21 |
-
max_tokens: int = Field(512, description="Maximum number of tokens to generate.")
|
| 22 |
-
temperature: float = Field(1.0, description="Sampling temperature.")
|
| 23 |
-
top_p: float = Field(0.3, description="Top-p sampling threshold.")
|
| 24 |
-
presence_penalty: float = Field(0.5, description="Presence penalty.")
|
| 25 |
-
count_penalty: float = Field(0.5, description="Count penalty.")
|
| 26 |
-
penalty_decay: float = Field(0.996, description="Penalty decay factor.")
|
| 27 |
-
stop: List[str] = Field(["\n\n"], description="List of stop sequences.")
|
| 28 |
-
stop_tokens: List[int] = Field([0], description="List of stop tokens.")
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
class ModelConfig(BaseModel):
|
| 32 |
-
"""Configuration for each individual model."""
|
| 33 |
-
|
| 34 |
-
SERVICE_NAME: str = Field(..., description="Service name of the model.")
|
| 35 |
-
|
| 36 |
-
MODEL_FILE_PATH: Optional[str] = Field(None, description="Model file path.")
|
| 37 |
-
|
| 38 |
-
DOWNLOAD_MODEL_FILE_NAME: Optional[str] = Field(
|
| 39 |
-
None, description="Model name, should end with .pth"
|
| 40 |
-
)
|
| 41 |
-
DOWNLOAD_MODEL_REPO_ID: Optional[str] = Field(
|
| 42 |
-
None, description="Model repository ID on Hugging Face Hub."
|
| 43 |
-
)
|
| 44 |
-
DOWNLOAD_MODEL_DIR: Optional[str] = Field(
|
| 45 |
-
None, description="Directory to download the model to."
|
| 46 |
-
)
|
| 47 |
-
|
| 48 |
-
REASONING: bool = Field(
|
| 49 |
-
False, description="Whether reasoning is enabled for this model."
|
| 50 |
-
)
|
| 51 |
-
|
| 52 |
-
DEFAULT_CHAT: bool = Field(False, description="Whether this model is the default chat model.")
|
| 53 |
-
DEFAULT_REASONING: bool = Field(False, description="Whether this model is the default reasoning model.")
|
| 54 |
-
DEFAULT_SAMPLER: SamplerConfig = Field(
|
| 55 |
-
SamplerConfig(), description="Default sampler configuration for this model."
|
| 56 |
-
)
|
| 57 |
-
VOCAB: str = Field("rwkv_vocab_v20230424", description="Vocab Name")
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
class RootConfig(BaseModel):
|
| 61 |
-
"""Root configuration for the RWKV service."""
|
| 62 |
-
|
| 63 |
-
HOST: Optional[str] = Field(
|
| 64 |
-
"127.0.0.1", description="Host IP address to bind to."
|
| 65 |
-
) # 注释掉可选的HOST和PORT
|
| 66 |
-
PORT: Optional[int] = Field(
|
| 67 |
-
8000, description="Port number to listen on."
|
| 68 |
-
) # 因为YAML示例中被注释掉了
|
| 69 |
-
STRATEGY: str = Field(
|
| 70 |
-
"cpu", description="Strategy for model execution (e.g., 'cuda fp16')."
|
| 71 |
-
)
|
| 72 |
-
RWKV_CUDA_ON: bool = Field(False, description="Whether to enable RWKV CUDA kernel.")
|
| 73 |
-
CHUNK_LEN: int = Field(256, description="Chunk length for processing.")
|
| 74 |
-
MODELS: List[ModelConfig] = Field(..., description="List of model configurations.")
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
import yaml
|
| 78 |
-
|
| 79 |
-
try:
|
| 80 |
-
with open(CLI_CONFIG.CONFIG_FILE, "r", encoding="utf-8") as f:
|
| 81 |
-
CONFIG = RootConfig.model_validate(yaml.safe_load(f.read()))
|
| 82 |
-
except Exception as e:
|
| 83 |
-
print(f"Pydantic Model Validation Failed: {e}")
|
| 84 |
-
sys.exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda/gemm_fp16_cublas.cpp
DELETED
|
@@ -1,75 +0,0 @@
|
|
| 1 |
-
#include <cublas_v2.h>
|
| 2 |
-
#include <cuda.h>
|
| 3 |
-
#include <cuda_fp16.h>
|
| 4 |
-
#include <cuda_runtime.h>
|
| 5 |
-
#include <torch/extension.h>
|
| 6 |
-
#include <c10/cuda/CUDAGuard.h>
|
| 7 |
-
#include <ATen/cuda/CUDAContext.h>
|
| 8 |
-
|
| 9 |
-
#define CUBLAS_CHECK(condition) \
|
| 10 |
-
for (cublasStatus_t _cublas_check_status = (condition); \
|
| 11 |
-
_cublas_check_status != CUBLAS_STATUS_SUCCESS;) \
|
| 12 |
-
throw std::runtime_error("cuBLAS error " + \
|
| 13 |
-
std::to_string(_cublas_check_status) + " at " + \
|
| 14 |
-
std::to_string(__LINE__));
|
| 15 |
-
|
| 16 |
-
#define CUDA_CHECK(condition) \
|
| 17 |
-
for (cudaError_t _cuda_check_status = (condition); \
|
| 18 |
-
_cuda_check_status != cudaSuccess;) \
|
| 19 |
-
throw std::runtime_error( \
|
| 20 |
-
"CUDA error " + std::string(cudaGetErrorString(_cuda_check_status)) + \
|
| 21 |
-
" at " + std::to_string(__LINE__));
|
| 22 |
-
|
| 23 |
-
/*
|
| 24 |
-
NOTE: blas gemm is column-major by default, but we need row-major output.
|
| 25 |
-
The data of row-major, transposed matrix is exactly the same as the
|
| 26 |
-
column-major, non-transposed matrix, and C = A * B ---> C^T = B^T * A^T
|
| 27 |
-
*/
|
| 28 |
-
void gemm_fp16_cublas(torch::Tensor a, torch::Tensor b, torch::Tensor c) {
|
| 29 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(a));
|
| 30 |
-
const auto cuda_data_type = CUDA_R_16F;
|
| 31 |
-
const auto cuda_c_data_type =
|
| 32 |
-
c.dtype() == torch::kFloat32 ? CUDA_R_32F : CUDA_R_16F;
|
| 33 |
-
const auto compute_type = CUDA_R_32F;
|
| 34 |
-
const float sp_alpha = 1.f;
|
| 35 |
-
// swap a and b, and use CUBLAS_OP_N. see the notes above
|
| 36 |
-
std::swap(a, b);
|
| 37 |
-
const cublasOperation_t cublas_trans_a = CUBLAS_OP_N;
|
| 38 |
-
const cublasOperation_t cublas_trans_b = CUBLAS_OP_N;
|
| 39 |
-
// m = (B^T).size(0) = B.size(1), and = A.size(1) after swap,
|
| 40 |
-
// negative axis is used because of the existence of batch matmul.
|
| 41 |
-
const int m = a.size(-1);
|
| 42 |
-
const int k = a.size(-2);
|
| 43 |
-
const int n = b.size(-2);
|
| 44 |
-
const int cublas_lda = m;
|
| 45 |
-
const int cublas_ldb = k;
|
| 46 |
-
const int cublas_ldc = m;
|
| 47 |
-
cublasHandle_t cublas_handle = at::cuda::getCurrentCUDABlasHandle();
|
| 48 |
-
|
| 49 |
-
#if CUDA_VERSION >= 11000
|
| 50 |
-
cublasGemmAlgo_t algo = CUBLAS_GEMM_DEFAULT;
|
| 51 |
-
#else
|
| 52 |
-
cublasGemmAlgo_t algo = CUBLAS_GEMM_DFALT_TENSOR_OP;
|
| 53 |
-
#endif
|
| 54 |
-
const float sp_beta = 0.f;
|
| 55 |
-
if (a.sizes().size() == 2 && b.sizes().size() == 2) {
|
| 56 |
-
CUBLAS_CHECK(cublasGemmEx(
|
| 57 |
-
cublas_handle, cublas_trans_a, cublas_trans_b, m, n, k, &sp_alpha,
|
| 58 |
-
a.data_ptr(), cuda_data_type, cublas_lda, b.data_ptr(), cuda_data_type,
|
| 59 |
-
cublas_ldb, &sp_beta, c.data_ptr(), cuda_c_data_type, cublas_ldc,
|
| 60 |
-
compute_type, algo));
|
| 61 |
-
} else {
|
| 62 |
-
// batch matmul
|
| 63 |
-
assert(a.sizes().size() == 3 && b.sizes().size() == 3);
|
| 64 |
-
|
| 65 |
-
const long long int cublas_stride_a = m * k;
|
| 66 |
-
const long long int cublas_stride_b = k * n;
|
| 67 |
-
const long long int cublas_stride_c = m * n;
|
| 68 |
-
CUBLAS_CHECK(cublasGemmStridedBatchedEx(
|
| 69 |
-
cublas_handle, cublas_trans_a, cublas_trans_b, m,
|
| 70 |
-
n, k, &sp_alpha, a.data_ptr(), cuda_data_type, cublas_lda,
|
| 71 |
-
cublas_stride_a, b.data_ptr(), cuda_data_type, cublas_ldb, cublas_stride_b,
|
| 72 |
-
&sp_beta, c.data_ptr(), cuda_c_data_type, cublas_ldc, cublas_stride_c,
|
| 73 |
-
a.size(0), compute_type, algo));
|
| 74 |
-
}
|
| 75 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda/operators.cu
DELETED
|
@@ -1,246 +0,0 @@
|
|
| 1 |
-
#include <stdio.h>
|
| 2 |
-
#include <assert.h>
|
| 3 |
-
#include "ATen/ATen.h"
|
| 4 |
-
#include <cuda_fp16.h>
|
| 5 |
-
#define MIN_VALUE (-1e38)
|
| 6 |
-
typedef at::Half fp16;
|
| 7 |
-
__half *cast(fp16 *ptr) {
|
| 8 |
-
return reinterpret_cast<__half *>(ptr);
|
| 9 |
-
}
|
| 10 |
-
|
| 11 |
-
template <typename F>
|
| 12 |
-
__global__ void kernel_wkv_forward(const int B, const int T, const int C,
|
| 13 |
-
const float *__restrict__ const _w, const float *__restrict__ const _u, const F *__restrict__ const _k, const F *__restrict__ const _v,
|
| 14 |
-
F *__restrict__ const _y, float *__restrict__ const _aa, float *__restrict__ const _bb, float *__restrict__ const _pp) {
|
| 15 |
-
const int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
| 16 |
-
const int _b = idx / C;
|
| 17 |
-
const int _c = idx % C;
|
| 18 |
-
const int _offset = _b * T * C + _c;
|
| 19 |
-
const int _state_offset = _b * C + _c;
|
| 20 |
-
|
| 21 |
-
float u = _u[_c];
|
| 22 |
-
float w = _w[_c];
|
| 23 |
-
const F *__restrict__ const k = _k + _offset;
|
| 24 |
-
const F *__restrict__ const v = _v + _offset;
|
| 25 |
-
F *__restrict__ const y = _y + _offset;
|
| 26 |
-
|
| 27 |
-
float aa = _aa[_state_offset];
|
| 28 |
-
float bb = _bb[_state_offset];
|
| 29 |
-
float pp = _pp[_state_offset];
|
| 30 |
-
for (int i = 0; i < T; i++) {
|
| 31 |
-
const int ii = i * C;
|
| 32 |
-
const float kk = float(k[ii]);
|
| 33 |
-
const float vv = float(v[ii]);
|
| 34 |
-
float ww = u + kk;
|
| 35 |
-
float p = max(pp, ww);
|
| 36 |
-
float e1 = exp(pp - p);
|
| 37 |
-
float e2 = exp(ww - p);
|
| 38 |
-
y[ii] = F((e1 * aa + e2 * vv) / (e1 * bb + e2));
|
| 39 |
-
ww = w + pp;
|
| 40 |
-
p = max(ww, kk);
|
| 41 |
-
e1 = exp(ww - p);
|
| 42 |
-
e2 = exp(kk - p);
|
| 43 |
-
aa = e1 * aa + e2 * vv;
|
| 44 |
-
bb = e1 * bb + e2;
|
| 45 |
-
pp = p;
|
| 46 |
-
}
|
| 47 |
-
_aa[_state_offset] = aa;
|
| 48 |
-
_bb[_state_offset] = bb;
|
| 49 |
-
_pp[_state_offset] = pp;
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
template <typename F>
|
| 53 |
-
void cuda_wkv_forward(int B, int T, int C, float *w, float *u, F *k, F *v, F *y, float *aa, float *bb, float *pp) {
|
| 54 |
-
dim3 threadsPerBlock( min(C, 32) );
|
| 55 |
-
assert(B * C % threadsPerBlock.x == 0);
|
| 56 |
-
dim3 numBlocks(B * C / threadsPerBlock.x);
|
| 57 |
-
kernel_wkv_forward<<<numBlocks, threadsPerBlock>>>(B, T, C, w, u, k, v, y, aa, bb, pp);
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
template void cuda_wkv_forward<fp16>(
|
| 61 |
-
int B, int T, int C,
|
| 62 |
-
float *w, float *u, fp16 *k, fp16 *v, fp16 *y,
|
| 63 |
-
float *aa, float *bb, float *pp);
|
| 64 |
-
template void cuda_wkv_forward<float>(
|
| 65 |
-
int B, int T, int C,
|
| 66 |
-
float *w, float *u, float *k, float *v, float *y,
|
| 67 |
-
float *aa, float *bb, float *pp);
|
| 68 |
-
|
| 69 |
-
__global__ void kernel_mm_seq_fp32i8(
|
| 70 |
-
const int B, const int N, const int M,
|
| 71 |
-
const float *__restrict__ const x, const int x_stride,
|
| 72 |
-
const uint8_t *__restrict__ const w, const int w_stride,
|
| 73 |
-
const float *__restrict__ const mx,
|
| 74 |
-
const float *__restrict__ const rx,
|
| 75 |
-
const float *__restrict__ const my,
|
| 76 |
-
const float *__restrict__ const ry,
|
| 77 |
-
float *__restrict__ const y, const int y_stride) {
|
| 78 |
-
|
| 79 |
-
const int i = blockIdx.x * blockDim.x + threadIdx.x;
|
| 80 |
-
const int k = blockIdx.y * blockDim.y + threadIdx.y;
|
| 81 |
-
|
| 82 |
-
if (i < B && k < M) {
|
| 83 |
-
float y_local = 0;
|
| 84 |
-
for (int j = 0; j < N; ++j) {
|
| 85 |
-
y_local += x[i * x_stride + j] * (
|
| 86 |
-
(float(w[j * w_stride + k]) + 0.5f)
|
| 87 |
-
* rx[k] * ry[j] + mx[k] + my[j]
|
| 88 |
-
);
|
| 89 |
-
}
|
| 90 |
-
y[i * y_stride + k] = y_local;
|
| 91 |
-
}
|
| 92 |
-
}
|
| 93 |
-
|
| 94 |
-
template <typename F>
|
| 95 |
-
void cuda_mm8_seq(int B, int N, int M,
|
| 96 |
-
F *x, int x_stride,
|
| 97 |
-
uint8_t *w, int w_stride,
|
| 98 |
-
F *mx, F *rx,
|
| 99 |
-
F *my, F *ry,
|
| 100 |
-
F *y, int y_stride);
|
| 101 |
-
|
| 102 |
-
template <>
|
| 103 |
-
void cuda_mm8_seq<float>(int B, int N, int M,
|
| 104 |
-
float *x, int x_stride,
|
| 105 |
-
uint8_t *w, int w_stride,
|
| 106 |
-
float *mx, float *rx,
|
| 107 |
-
float *my, float *ry,
|
| 108 |
-
float *y, int y_stride) {
|
| 109 |
-
dim3 blockSize(1, 128);
|
| 110 |
-
dim3 gridSize((B + blockSize.x - 1) / blockSize.x, (M + blockSize.y - 1) / blockSize.y);
|
| 111 |
-
kernel_mm_seq_fp32i8<<<gridSize, blockSize>>>(
|
| 112 |
-
B, N, M, x, x_stride, w, w_stride,
|
| 113 |
-
mx, rx, my, ry, y, y_stride);
|
| 114 |
-
}
|
| 115 |
-
|
| 116 |
-
__global__ void kernel_mm_seq_fp16i8(
|
| 117 |
-
const int B, const int N, const int M,
|
| 118 |
-
const __half *__restrict__ const x, const int x_stride,
|
| 119 |
-
const uint8_t *__restrict__ const w, const int w_stride,
|
| 120 |
-
const __half *__restrict__ const mx,
|
| 121 |
-
const __half *__restrict__ const rx,
|
| 122 |
-
const __half *__restrict__ const my,
|
| 123 |
-
const __half *__restrict__ const ry,
|
| 124 |
-
__half *__restrict__ const y, const int y_stride) {
|
| 125 |
-
|
| 126 |
-
const int i = blockIdx.x * blockDim.x + threadIdx.x;
|
| 127 |
-
const int k = blockIdx.y * blockDim.y + threadIdx.y;
|
| 128 |
-
|
| 129 |
-
if (i < B && k < M) {
|
| 130 |
-
float y_local = 0;
|
| 131 |
-
for (int j = 0; j < N; ++j) {
|
| 132 |
-
y_local += __half2float(x[i * x_stride + j]) * (
|
| 133 |
-
(float(w[j * w_stride + k]) + 0.5f)
|
| 134 |
-
* __half2float(rx[k]) * __half2float(ry[j])
|
| 135 |
-
+ __half2float(mx[k]) + __half2float(my[j])
|
| 136 |
-
);
|
| 137 |
-
}
|
| 138 |
-
y[i * y_stride + k] = __float2half(y_local);
|
| 139 |
-
}
|
| 140 |
-
}
|
| 141 |
-
|
| 142 |
-
template <>
|
| 143 |
-
void cuda_mm8_seq<fp16>(int B, int N, int M,
|
| 144 |
-
fp16 *x, int x_stride,
|
| 145 |
-
uint8_t *w, int w_stride,
|
| 146 |
-
fp16 *mx, fp16 *rx,
|
| 147 |
-
fp16 *my, fp16 *ry,
|
| 148 |
-
fp16 *y, int y_stride) {
|
| 149 |
-
dim3 blockSize(1, 128);
|
| 150 |
-
dim3 gridSize((B + blockSize.x - 1) / blockSize.x, (M + blockSize.y - 1) / blockSize.y);
|
| 151 |
-
kernel_mm_seq_fp16i8<<<gridSize, blockSize>>>(
|
| 152 |
-
B, N, M, cast(x), x_stride, w, w_stride,
|
| 153 |
-
cast(mx), cast(rx), cast(my), cast(ry), cast(y), y_stride);
|
| 154 |
-
}
|
| 155 |
-
|
| 156 |
-
#define MM8_ONE_JSPLIT 24
|
| 157 |
-
#define MM8_ONE_TILE 1024
|
| 158 |
-
|
| 159 |
-
__global__ void kernel_mm_one_fp32i8(
|
| 160 |
-
const int N, const int M,
|
| 161 |
-
const float *__restrict__ const x,
|
| 162 |
-
const uint8_t *__restrict__ const w, const int w_stride,
|
| 163 |
-
const float *__restrict__ const mx,
|
| 164 |
-
const float *__restrict__ const rx,
|
| 165 |
-
const float *__restrict__ const my,
|
| 166 |
-
const float *__restrict__ const ry,
|
| 167 |
-
float *__restrict__ const y) {
|
| 168 |
-
|
| 169 |
-
const int k = blockIdx.y * blockDim.y + threadIdx.y;
|
| 170 |
-
const int j0 = min(N, blockIdx.x * ((N + MM8_ONE_JSPLIT - 1) / MM8_ONE_JSPLIT));
|
| 171 |
-
const int j1 = min(N, (blockIdx.x + 1) * ((N + MM8_ONE_JSPLIT - 1) / MM8_ONE_JSPLIT));
|
| 172 |
-
|
| 173 |
-
if (k < M) {
|
| 174 |
-
float y_local = 0;
|
| 175 |
-
for (int j = j0; j < j1; ++j) {
|
| 176 |
-
y_local += x[j] * (
|
| 177 |
-
(float(w[j * w_stride + k]) + 0.5f)
|
| 178 |
-
* rx[k] * ry[j] + mx[k] + my[j]
|
| 179 |
-
);
|
| 180 |
-
}
|
| 181 |
-
atomicAdd(&y[k], y_local);
|
| 182 |
-
}
|
| 183 |
-
}
|
| 184 |
-
|
| 185 |
-
template <typename F>
|
| 186 |
-
void cuda_mm8_one(int N, int M,
|
| 187 |
-
F *x,
|
| 188 |
-
uint8_t *w, int w_stride,
|
| 189 |
-
F *mx, F *rx,
|
| 190 |
-
F *my, F *ry,
|
| 191 |
-
float *y);
|
| 192 |
-
|
| 193 |
-
template <>
|
| 194 |
-
void cuda_mm8_one<float>(int N, int M,
|
| 195 |
-
float *x,
|
| 196 |
-
uint8_t *w, int w_stride,
|
| 197 |
-
float *mx, float *rx,
|
| 198 |
-
float *my, float *ry,
|
| 199 |
-
float *y) {
|
| 200 |
-
dim3 blockSize(1, MM8_ONE_TILE);
|
| 201 |
-
dim3 gridSize(MM8_ONE_JSPLIT, (M + blockSize.y - 1) / blockSize.y);
|
| 202 |
-
kernel_mm_one_fp32i8<<<gridSize, blockSize>>>(
|
| 203 |
-
N, M, x, w, w_stride,
|
| 204 |
-
mx, rx, my, ry, y);
|
| 205 |
-
}
|
| 206 |
-
|
| 207 |
-
__global__ void kernel_mm_one_fp16i8(
|
| 208 |
-
const int N, const int M,
|
| 209 |
-
const __half *__restrict__ const x,
|
| 210 |
-
const uint8_t *__restrict__ const w, const int w_stride,
|
| 211 |
-
const __half *__restrict__ const mx,
|
| 212 |
-
const __half *__restrict__ const rx,
|
| 213 |
-
const __half *__restrict__ const my,
|
| 214 |
-
const __half *__restrict__ const ry,
|
| 215 |
-
float *__restrict__ const y) {
|
| 216 |
-
|
| 217 |
-
const int k = blockIdx.y * blockDim.y + threadIdx.y;
|
| 218 |
-
const int j0 = min(N, blockIdx.x * ((N + MM8_ONE_JSPLIT - 1) / MM8_ONE_JSPLIT));
|
| 219 |
-
const int j1 = min(N, (blockIdx.x + 1) * ((N + MM8_ONE_JSPLIT - 1) / MM8_ONE_JSPLIT));
|
| 220 |
-
|
| 221 |
-
if (k < M) {
|
| 222 |
-
float y_local = 0;
|
| 223 |
-
for (int j = j0; j < j1; ++j) {
|
| 224 |
-
y_local += __half2float(x[j]) * (
|
| 225 |
-
(float(w[j * w_stride + k]) + 0.5f)
|
| 226 |
-
* __half2float(rx[k]) * __half2float(ry[j])
|
| 227 |
-
+ __half2float(mx[k]) + __half2float(my[j])
|
| 228 |
-
);
|
| 229 |
-
}
|
| 230 |
-
atomicAdd(&y[k], y_local);
|
| 231 |
-
}
|
| 232 |
-
}
|
| 233 |
-
|
| 234 |
-
template <>
|
| 235 |
-
void cuda_mm8_one<fp16>(int N, int M,
|
| 236 |
-
fp16 *x,
|
| 237 |
-
uint8_t *w, int w_stride,
|
| 238 |
-
fp16 *mx, fp16 *rx,
|
| 239 |
-
fp16 *my, fp16 *ry,
|
| 240 |
-
float *y) {
|
| 241 |
-
dim3 blockSize(1, MM8_ONE_TILE);
|
| 242 |
-
dim3 gridSize(MM8_ONE_JSPLIT, (M + blockSize.y - 1) / blockSize.y);
|
| 243 |
-
kernel_mm_one_fp16i8<<<gridSize, blockSize>>>(
|
| 244 |
-
N, M, cast(x), w, w_stride,
|
| 245 |
-
cast(mx), cast(rx), cast(my), cast(ry), y);
|
| 246 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda/rwkv5.cu
DELETED
|
@@ -1,88 +0,0 @@
|
|
| 1 |
-
#include <stdio.h>
|
| 2 |
-
#include <assert.h>
|
| 3 |
-
#include "ATen/ATen.h"
|
| 4 |
-
typedef at::BFloat16 bf16;
|
| 5 |
-
typedef at::Half fp16;
|
| 6 |
-
typedef float fp32;
|
| 7 |
-
|
| 8 |
-
template <typename F>
|
| 9 |
-
__global__ void kernel_forward(const int B, const int T, const int C, const int H, float *__restrict__ _state,
|
| 10 |
-
const F *__restrict__ const _r, const F *__restrict__ const _k, const F *__restrict__ const _v, const float *__restrict__ _w, const F *__restrict__ _u,
|
| 11 |
-
F *__restrict__ const _y)
|
| 12 |
-
{
|
| 13 |
-
const int b = blockIdx.x / H;
|
| 14 |
-
const int h = blockIdx.x % H;
|
| 15 |
-
const int i = threadIdx.x;
|
| 16 |
-
_w += h*_N_;
|
| 17 |
-
_u += h*_N_;
|
| 18 |
-
_state += h*_N_*_N_ + i*_N_; // wrong if B > 1 !!!
|
| 19 |
-
|
| 20 |
-
__shared__ float r[_N_], k[_N_], u[_N_], w[_N_];
|
| 21 |
-
|
| 22 |
-
float state[_N_];
|
| 23 |
-
#pragma unroll
|
| 24 |
-
for (int j = 0; j < _N_; j++)
|
| 25 |
-
state[j] = _state[j];
|
| 26 |
-
|
| 27 |
-
__syncthreads();
|
| 28 |
-
u[i] = float(_u[i]);
|
| 29 |
-
w[i] = _w[i];
|
| 30 |
-
__syncthreads();
|
| 31 |
-
|
| 32 |
-
for (int t = b*T*C + h*_N_ + i; t < (b+1)*T*C + h*_N_ + i; t += C)
|
| 33 |
-
{
|
| 34 |
-
__syncthreads();
|
| 35 |
-
r[i] = float(_r[t]);
|
| 36 |
-
k[i] = float(_k[t]);
|
| 37 |
-
__syncthreads();
|
| 38 |
-
|
| 39 |
-
const float v = float(_v[t]);
|
| 40 |
-
float y = 0;
|
| 41 |
-
|
| 42 |
-
#pragma unroll
|
| 43 |
-
for (int j = 0; j < _N_; j+=4)
|
| 44 |
-
{
|
| 45 |
-
const float4& r_ = (float4&)(r[j]);
|
| 46 |
-
const float4& k_ = (float4&)(k[j]);
|
| 47 |
-
const float4& w_ = (float4&)(w[j]);
|
| 48 |
-
const float4& u_ = (float4&)(u[j]);
|
| 49 |
-
float4& s = (float4&)(state[j]);
|
| 50 |
-
float4 x;
|
| 51 |
-
|
| 52 |
-
x.x = k_.x * v;
|
| 53 |
-
x.y = k_.y * v;
|
| 54 |
-
x.z = k_.z * v;
|
| 55 |
-
x.w = k_.w * v;
|
| 56 |
-
|
| 57 |
-
y += r_.x * (u_.x * x.x + s.x);
|
| 58 |
-
y += r_.y * (u_.y * x.y + s.y);
|
| 59 |
-
y += r_.z * (u_.z * x.z + s.z);
|
| 60 |
-
y += r_.w * (u_.w * x.w + s.w);
|
| 61 |
-
|
| 62 |
-
s.x = s.x * w_.x + x.x;
|
| 63 |
-
s.y = s.y * w_.y + x.y;
|
| 64 |
-
s.z = s.z * w_.z + x.z;
|
| 65 |
-
s.w = s.w * w_.w + x.w;
|
| 66 |
-
}
|
| 67 |
-
_y[t] = F(y);
|
| 68 |
-
}
|
| 69 |
-
#pragma unroll
|
| 70 |
-
for (int j = 0; j < _N_; j++)
|
| 71 |
-
_state[j] = state[j];
|
| 72 |
-
}
|
| 73 |
-
|
| 74 |
-
void cuda_forward_bf16(int B, int T, int C, int H, float *state, bf16 *r, bf16 *k, bf16 *v, float *w, bf16 *u, bf16 *y)
|
| 75 |
-
{
|
| 76 |
-
assert(H*_N_ == C);
|
| 77 |
-
kernel_forward<<<dim3(B * H), dim3(_N_)>>>(B, T, C, H, state, r, k, v, w, u, y);
|
| 78 |
-
}
|
| 79 |
-
void cuda_forward_fp16(int B, int T, int C, int H, float *state, fp16 *r, fp16 *k, fp16 *v, float *w, fp16 *u, fp16 *y)
|
| 80 |
-
{
|
| 81 |
-
assert(H*_N_ == C);
|
| 82 |
-
kernel_forward<<<dim3(B * H), dim3(_N_)>>>(B, T, C, H, state, r, k, v, w, u, y);
|
| 83 |
-
}
|
| 84 |
-
void cuda_forward_fp32(int B, int T, int C, int H, float *state, fp32 *r, fp32 *k, fp32 *v, float *w, fp32 *u, fp32 *y)
|
| 85 |
-
{
|
| 86 |
-
assert(H*_N_ == C);
|
| 87 |
-
kernel_forward<<<dim3(B * H), dim3(_N_)>>>(B, T, C, H, state, r, k, v, w, u, y);
|
| 88 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda/rwkv5_op.cpp
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
#include <torch/extension.h>
|
| 2 |
-
#include "ATen/ATen.h"
|
| 3 |
-
#include <c10/cuda/CUDAGuard.h>
|
| 4 |
-
typedef at::BFloat16 bf16;
|
| 5 |
-
typedef at::Half fp16;
|
| 6 |
-
typedef float fp32;
|
| 7 |
-
|
| 8 |
-
void cuda_forward_bf16(int B, int T, int C, int H, float *state, bf16 *r, bf16 *k, bf16 *v, float *w, bf16 *u, bf16 *y);
|
| 9 |
-
void cuda_forward_fp16(int B, int T, int C, int H, float *state, fp16 *r, fp16 *k, fp16 *v, float *w, fp16 *u, fp16 *y);
|
| 10 |
-
void cuda_forward_fp32(int B, int T, int C, int H, float *state, fp32 *r, fp32 *k, fp32 *v, float *w, fp32 *u, fp32 *y);
|
| 11 |
-
|
| 12 |
-
void forward_bf16(int64_t B, int64_t T, int64_t C, int64_t H, torch::Tensor &state, torch::Tensor &r, torch::Tensor &k, torch::Tensor &v, torch::Tensor &w, torch::Tensor &u, torch::Tensor &y) {
|
| 13 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(state));
|
| 14 |
-
cuda_forward_bf16(B, T, C, H, state.data_ptr<float>(), r.data_ptr<bf16>(), k.data_ptr<bf16>(), v.data_ptr<bf16>(), w.data_ptr<float>(), u.data_ptr<bf16>(), y.data_ptr<bf16>());
|
| 15 |
-
}
|
| 16 |
-
void forward_fp16(int64_t B, int64_t T, int64_t C, int64_t H, torch::Tensor &state, torch::Tensor &r, torch::Tensor &k, torch::Tensor &v, torch::Tensor &w, torch::Tensor &u, torch::Tensor &y) {
|
| 17 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(state));
|
| 18 |
-
cuda_forward_fp16(B, T, C, H, state.data_ptr<float>(), r.data_ptr<fp16>(), k.data_ptr<fp16>(), v.data_ptr<fp16>(), w.data_ptr<float>(), u.data_ptr<fp16>(), y.data_ptr<fp16>());
|
| 19 |
-
}
|
| 20 |
-
void forward_fp32(int64_t B, int64_t T, int64_t C, int64_t H, torch::Tensor &state, torch::Tensor &r, torch::Tensor &k, torch::Tensor &v, torch::Tensor &w, torch::Tensor &u, torch::Tensor &y) {
|
| 21 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(state));
|
| 22 |
-
cuda_forward_fp32(B, T, C, H, state.data_ptr<float>(), r.data_ptr<fp32>(), k.data_ptr<fp32>(), v.data_ptr<fp32>(), w.data_ptr<float>(), u.data_ptr<fp32>(), y.data_ptr<fp32>());
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
|
| 26 |
-
m.def("forward_bf16", &forward_bf16, "rwkv5 forward_bf16");
|
| 27 |
-
m.def("forward_fp16", &forward_fp16, "rwkv5 forward_fp16");
|
| 28 |
-
m.def("forward_fp32", &forward_fp32, "rwkv5 forward_fp32");
|
| 29 |
-
}
|
| 30 |
-
TORCH_LIBRARY(rwkv5, m) {
|
| 31 |
-
m.def("forward_bf16", forward_bf16);
|
| 32 |
-
m.def("forward_fp16", forward_fp16);
|
| 33 |
-
m.def("forward_fp32", forward_fp32);
|
| 34 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda/rwkv6.cu
DELETED
|
@@ -1,87 +0,0 @@
|
|
| 1 |
-
#include <stdio.h>
|
| 2 |
-
#include <assert.h>
|
| 3 |
-
#include "ATen/ATen.h"
|
| 4 |
-
typedef at::BFloat16 bf16;
|
| 5 |
-
typedef at::Half fp16;
|
| 6 |
-
typedef float fp32;
|
| 7 |
-
|
| 8 |
-
template <typename F>
|
| 9 |
-
__global__ void kernel_forward(const int B, const int T, const int C, const int H, float *__restrict__ _state,
|
| 10 |
-
const F *__restrict__ const _r, const F *__restrict__ const _k, const F *__restrict__ const _v, const float *__restrict__ _w, const F *__restrict__ _u,
|
| 11 |
-
F *__restrict__ const _y)
|
| 12 |
-
{
|
| 13 |
-
const int b = blockIdx.x / H;
|
| 14 |
-
const int h = blockIdx.x % H;
|
| 15 |
-
const int i = threadIdx.x;
|
| 16 |
-
_u += h*_N_;
|
| 17 |
-
_state += h*_N_*_N_ + i*_N_; // wrong if B > 1 !!!
|
| 18 |
-
|
| 19 |
-
__shared__ float r[_N_], k[_N_], u[_N_], w[_N_];
|
| 20 |
-
|
| 21 |
-
float state[_N_];
|
| 22 |
-
#pragma unroll
|
| 23 |
-
for (int j = 0; j < _N_; j++)
|
| 24 |
-
state[j] = _state[j];
|
| 25 |
-
|
| 26 |
-
__syncthreads();
|
| 27 |
-
u[i] = float(_u[i]);
|
| 28 |
-
__syncthreads();
|
| 29 |
-
|
| 30 |
-
for (int t = b*T*C + h*_N_ + i; t < (b+1)*T*C + h*_N_ + i; t += C)
|
| 31 |
-
{
|
| 32 |
-
__syncthreads();
|
| 33 |
-
w[i] = _w[t];
|
| 34 |
-
r[i] = float(_r[t]);
|
| 35 |
-
k[i] = float(_k[t]);
|
| 36 |
-
__syncthreads();
|
| 37 |
-
|
| 38 |
-
const float v = float(_v[t]);
|
| 39 |
-
float y = 0;
|
| 40 |
-
|
| 41 |
-
#pragma unroll
|
| 42 |
-
for (int j = 0; j < _N_; j+=4)
|
| 43 |
-
{
|
| 44 |
-
const float4& r_ = (float4&)(r[j]);
|
| 45 |
-
const float4& k_ = (float4&)(k[j]);
|
| 46 |
-
const float4& w_ = (float4&)(w[j]);
|
| 47 |
-
const float4& u_ = (float4&)(u[j]);
|
| 48 |
-
float4& s = (float4&)(state[j]);
|
| 49 |
-
float4 x;
|
| 50 |
-
|
| 51 |
-
x.x = k_.x * v;
|
| 52 |
-
x.y = k_.y * v;
|
| 53 |
-
x.z = k_.z * v;
|
| 54 |
-
x.w = k_.w * v;
|
| 55 |
-
|
| 56 |
-
y += r_.x * (u_.x * x.x + s.x);
|
| 57 |
-
y += r_.y * (u_.y * x.y + s.y);
|
| 58 |
-
y += r_.z * (u_.z * x.z + s.z);
|
| 59 |
-
y += r_.w * (u_.w * x.w + s.w);
|
| 60 |
-
|
| 61 |
-
s.x = s.x * w_.x + x.x;
|
| 62 |
-
s.y = s.y * w_.y + x.y;
|
| 63 |
-
s.z = s.z * w_.z + x.z;
|
| 64 |
-
s.w = s.w * w_.w + x.w;
|
| 65 |
-
}
|
| 66 |
-
_y[t] = F(y);
|
| 67 |
-
}
|
| 68 |
-
#pragma unroll
|
| 69 |
-
for (int j = 0; j < _N_; j++)
|
| 70 |
-
_state[j] = state[j];
|
| 71 |
-
}
|
| 72 |
-
|
| 73 |
-
void cuda_forward_bf16(int B, int T, int C, int H, float *state, bf16 *r, bf16 *k, bf16 *v, float *w, bf16 *u, bf16 *y)
|
| 74 |
-
{
|
| 75 |
-
assert(H*_N_ == C);
|
| 76 |
-
kernel_forward<<<dim3(B * H), dim3(_N_)>>>(B, T, C, H, state, r, k, v, w, u, y);
|
| 77 |
-
}
|
| 78 |
-
void cuda_forward_fp16(int B, int T, int C, int H, float *state, fp16 *r, fp16 *k, fp16 *v, float *w, fp16 *u, fp16 *y)
|
| 79 |
-
{
|
| 80 |
-
assert(H*_N_ == C);
|
| 81 |
-
kernel_forward<<<dim3(B * H), dim3(_N_)>>>(B, T, C, H, state, r, k, v, w, u, y);
|
| 82 |
-
}
|
| 83 |
-
void cuda_forward_fp32(int B, int T, int C, int H, float *state, fp32 *r, fp32 *k, fp32 *v, float *w, fp32 *u, fp32 *y)
|
| 84 |
-
{
|
| 85 |
-
assert(H*_N_ == C);
|
| 86 |
-
kernel_forward<<<dim3(B * H), dim3(_N_)>>>(B, T, C, H, state, r, k, v, w, u, y);
|
| 87 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda/rwkv6_op.cpp
DELETED
|
@@ -1,34 +0,0 @@
|
|
| 1 |
-
#include <torch/extension.h>
|
| 2 |
-
#include "ATen/ATen.h"
|
| 3 |
-
#include <c10/cuda/CUDAGuard.h>
|
| 4 |
-
typedef at::BFloat16 bf16;
|
| 5 |
-
typedef at::Half fp16;
|
| 6 |
-
typedef float fp32;
|
| 7 |
-
|
| 8 |
-
void cuda_forward_bf16(int B, int T, int C, int H, float *state, bf16 *r, bf16 *k, bf16 *v, float *w, bf16 *u, bf16 *y);
|
| 9 |
-
void cuda_forward_fp16(int B, int T, int C, int H, float *state, fp16 *r, fp16 *k, fp16 *v, float *w, fp16 *u, fp16 *y);
|
| 10 |
-
void cuda_forward_fp32(int B, int T, int C, int H, float *state, fp32 *r, fp32 *k, fp32 *v, float *w, fp32 *u, fp32 *y);
|
| 11 |
-
|
| 12 |
-
void forward_bf16(int64_t B, int64_t T, int64_t C, int64_t H, torch::Tensor &state, torch::Tensor &r, torch::Tensor &k, torch::Tensor &v, torch::Tensor &w, torch::Tensor &u, torch::Tensor &y) {
|
| 13 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(state));
|
| 14 |
-
cuda_forward_bf16(B, T, C, H, state.data_ptr<float>(), r.data_ptr<bf16>(), k.data_ptr<bf16>(), v.data_ptr<bf16>(), w.data_ptr<float>(), u.data_ptr<bf16>(), y.data_ptr<bf16>());
|
| 15 |
-
}
|
| 16 |
-
void forward_fp16(int64_t B, int64_t T, int64_t C, int64_t H, torch::Tensor &state, torch::Tensor &r, torch::Tensor &k, torch::Tensor &v, torch::Tensor &w, torch::Tensor &u, torch::Tensor &y) {
|
| 17 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(state));
|
| 18 |
-
cuda_forward_fp16(B, T, C, H, state.data_ptr<float>(), r.data_ptr<fp16>(), k.data_ptr<fp16>(), v.data_ptr<fp16>(), w.data_ptr<float>(), u.data_ptr<fp16>(), y.data_ptr<fp16>());
|
| 19 |
-
}
|
| 20 |
-
void forward_fp32(int64_t B, int64_t T, int64_t C, int64_t H, torch::Tensor &state, torch::Tensor &r, torch::Tensor &k, torch::Tensor &v, torch::Tensor &w, torch::Tensor &u, torch::Tensor &y) {
|
| 21 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(state));
|
| 22 |
-
cuda_forward_fp32(B, T, C, H, state.data_ptr<float>(), r.data_ptr<fp32>(), k.data_ptr<fp32>(), v.data_ptr<fp32>(), w.data_ptr<float>(), u.data_ptr<fp32>(), y.data_ptr<fp32>());
|
| 23 |
-
}
|
| 24 |
-
|
| 25 |
-
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
|
| 26 |
-
m.def("forward_bf16", &forward_bf16, "rwkv6 forward_bf16");
|
| 27 |
-
m.def("forward_fp16", &forward_fp16, "rwkv6 forward_fp16");
|
| 28 |
-
m.def("forward_fp32", &forward_fp32, "rwkv6 forward_fp32");
|
| 29 |
-
}
|
| 30 |
-
TORCH_LIBRARY(rwkv6, m) {
|
| 31 |
-
m.def("forward_bf16", forward_bf16);
|
| 32 |
-
m.def("forward_fp16", forward_fp16);
|
| 33 |
-
m.def("forward_fp32", forward_fp32);
|
| 34 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda/rwkv7.cu
DELETED
|
@@ -1,77 +0,0 @@
|
|
| 1 |
-
#include <stdio.h>
|
| 2 |
-
#include <assert.h>
|
| 3 |
-
#include "ATen/ATen.h"
|
| 4 |
-
|
| 5 |
-
typedef at::Half fp16;
|
| 6 |
-
typedef at::BFloat16 bf16;
|
| 7 |
-
typedef float fp32;
|
| 8 |
-
|
| 9 |
-
template <typename F>
|
| 10 |
-
__global__ void kernel_forward(const int B, const int T, const int C, const int H,
|
| 11 |
-
float *__restrict__ _state, const F *__restrict__ const _r, const F *__restrict__ const _w, const F *__restrict__ const _k, const F *__restrict__ const _v, const F *__restrict__ const _a, const F *__restrict__ const _b,
|
| 12 |
-
F *__restrict__ const _y)
|
| 13 |
-
{
|
| 14 |
-
const int e = blockIdx.x / H;
|
| 15 |
-
const int h = blockIdx.x % H;
|
| 16 |
-
const int i = threadIdx.x;
|
| 17 |
-
_state += h*_N_*_N_ + i*_N_; // wrong if B > 1 !!!
|
| 18 |
-
|
| 19 |
-
float state[_N_];
|
| 20 |
-
#pragma unroll
|
| 21 |
-
for (int j = 0; j < _N_; j++)
|
| 22 |
-
state[j] = _state[j];
|
| 23 |
-
|
| 24 |
-
__shared__ float r[_N_], k[_N_], w[_N_], a[_N_], b[_N_];
|
| 25 |
-
|
| 26 |
-
for (int _t = 0; _t < T; _t++)
|
| 27 |
-
{
|
| 28 |
-
const int t = e*T*C + h*_N_ + i + _t * C;
|
| 29 |
-
__syncthreads();
|
| 30 |
-
r[i] = float(_r[t]);
|
| 31 |
-
w[i] = __expf(-__expf(float(_w[t])));
|
| 32 |
-
k[i] = float(_k[t]);
|
| 33 |
-
a[i] = float(_a[t]);
|
| 34 |
-
b[i] = float(_b[t]);
|
| 35 |
-
__syncthreads();
|
| 36 |
-
|
| 37 |
-
float sa = 0;
|
| 38 |
-
#pragma unroll
|
| 39 |
-
for (int j = 0; j < _N_; j++)
|
| 40 |
-
{
|
| 41 |
-
sa += a[j] * state[j];
|
| 42 |
-
}
|
| 43 |
-
|
| 44 |
-
float vv = float(_v[t]);
|
| 45 |
-
float y = 0;
|
| 46 |
-
#pragma unroll
|
| 47 |
-
for (int j = 0; j < _N_; j++)
|
| 48 |
-
{
|
| 49 |
-
float& s = state[j];
|
| 50 |
-
s = s * w[j] + k[j] * vv + sa * b[j];
|
| 51 |
-
y += s * r[j];
|
| 52 |
-
}
|
| 53 |
-
_y[t] = F(y);
|
| 54 |
-
}
|
| 55 |
-
#pragma unroll
|
| 56 |
-
for (int j = 0; j < _N_; j++)
|
| 57 |
-
_state[j] = state[j];
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
void cuda_forward_bf16(int B, int T, int C, int H, float *state, bf16 *r, bf16* w, bf16 *k, bf16 *v, bf16 *a, bf16 *b, bf16 *y)
|
| 61 |
-
{
|
| 62 |
-
assert(H*_N_ == C);
|
| 63 |
-
assert(B == 1); // only for B=1
|
| 64 |
-
kernel_forward<<<dim3(B * H), dim3(_N_)>>>(B, T, C, H, state, r, w, k, v, a, b, y);
|
| 65 |
-
}
|
| 66 |
-
void cuda_forward_fp16(int B, int T, int C, int H, float *state, fp16 *r, fp16* w, fp16 *k, fp16 *v, fp16 *a, fp16 *b, fp16 *y)
|
| 67 |
-
{
|
| 68 |
-
assert(H*_N_ == C);
|
| 69 |
-
assert(B == 1); // only for B=1
|
| 70 |
-
kernel_forward<<<dim3(B * H), dim3(_N_)>>>(B, T, C, H, state, r, w, k, v, a, b, y);
|
| 71 |
-
}
|
| 72 |
-
void cuda_forward_fp32(int B, int T, int C, int H, float *state, fp32 *r, fp32* w, fp32 *k, fp32 *v, fp32 *a, fp32 *b, fp32 *y)
|
| 73 |
-
{
|
| 74 |
-
assert(H*_N_ == C);
|
| 75 |
-
assert(B == 1); // only for B=1
|
| 76 |
-
kernel_forward<<<dim3(B * H), dim3(_N_)>>>(B, T, C, H, state, r, w, k, v, a, b, y);
|
| 77 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda/rwkv7_op.cpp
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 1 |
-
#include <torch/extension.h>
|
| 2 |
-
#include "ATen/ATen.h"
|
| 3 |
-
|
| 4 |
-
typedef at::Half fp16;
|
| 5 |
-
typedef at::BFloat16 bf16;
|
| 6 |
-
typedef float fp32;
|
| 7 |
-
|
| 8 |
-
void cuda_forward_bf16(int B, int T, int C, int H, float *state, bf16 *r, bf16 *w, bf16 *k, bf16 *v, bf16 *a, bf16 *b, bf16 *y);
|
| 9 |
-
void cuda_forward_fp16(int B, int T, int C, int H, float *state, fp16 *r, fp16 *w, fp16 *k, fp16 *v, fp16 *a, fp16 *b, fp16 *y);
|
| 10 |
-
void cuda_forward_fp32(int B, int T, int C, int H, float *state, fp32 *r, fp32 *w, fp32 *k, fp32 *v, fp32 *a, fp32 *b, fp32 *y);
|
| 11 |
-
|
| 12 |
-
void forward_bf16(int64_t B, int64_t T, int64_t C, int64_t H, torch::Tensor &state, torch::Tensor &r, torch::Tensor &w, torch::Tensor &k, torch::Tensor &v, torch::Tensor &a, torch::Tensor &b, torch::Tensor &y) {
|
| 13 |
-
cuda_forward_bf16(B, T, C, H, state.data_ptr<float>(), r.data_ptr<bf16>(), w.data_ptr<bf16>(), k.data_ptr<bf16>(), v.data_ptr<bf16>(), a.data_ptr<bf16>(), b.data_ptr<bf16>(), y.data_ptr<bf16>());
|
| 14 |
-
}
|
| 15 |
-
void forward_fp16(int64_t B, int64_t T, int64_t C, int64_t H, torch::Tensor &state, torch::Tensor &r, torch::Tensor &w, torch::Tensor &k, torch::Tensor &v, torch::Tensor &a, torch::Tensor &b, torch::Tensor &y) {
|
| 16 |
-
cuda_forward_fp16(B, T, C, H, state.data_ptr<float>(), r.data_ptr<fp16>(), w.data_ptr<fp16>(), k.data_ptr<fp16>(), v.data_ptr<fp16>(), a.data_ptr<fp16>(), b.data_ptr<fp16>(), y.data_ptr<fp16>());
|
| 17 |
-
}
|
| 18 |
-
void forward_fp32(int64_t B, int64_t T, int64_t C, int64_t H, torch::Tensor &state, torch::Tensor &r, torch::Tensor &w, torch::Tensor &k, torch::Tensor &v, torch::Tensor &a, torch::Tensor &b, torch::Tensor &y) {
|
| 19 |
-
cuda_forward_fp32(B, T, C, H, state.data_ptr<float>(), r.data_ptr<fp32>(), w.data_ptr<fp32>(), k.data_ptr<fp32>(), v.data_ptr<fp32>(), a.data_ptr<fp32>(), b.data_ptr<fp32>(), y.data_ptr<fp32>());
|
| 20 |
-
}
|
| 21 |
-
|
| 22 |
-
TORCH_LIBRARY(wkv7s, m) {
|
| 23 |
-
m.def("forward_bf16", forward_bf16);
|
| 24 |
-
m.def("forward_fp16", forward_fp16);
|
| 25 |
-
m.def("forward_fp32", forward_fp32);
|
| 26 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cuda/wrapper.cpp
DELETED
|
@@ -1,141 +0,0 @@
|
|
| 1 |
-
#include <torch/extension.h>
|
| 2 |
-
#include "ATen/ATen.h"
|
| 3 |
-
#include <iostream>
|
| 4 |
-
#include <c10/cuda/CUDAGuard.h>
|
| 5 |
-
|
| 6 |
-
typedef at::Half fp16;
|
| 7 |
-
|
| 8 |
-
template <typename F>
|
| 9 |
-
void cuda_wkv_forward(int B, int T, int C,
|
| 10 |
-
float *w, float *u, F *k, F *v, F *y,
|
| 11 |
-
float *aa, float *bb, float *pp);
|
| 12 |
-
template <typename F>
|
| 13 |
-
void cuda_mm8_seq(int B, int N, int M,
|
| 14 |
-
F *x, int x_stride,
|
| 15 |
-
uint8_t *w, int w_stride,
|
| 16 |
-
F *mx, F *rx,
|
| 17 |
-
F *my, F *ry,
|
| 18 |
-
F *y, int y_stride);
|
| 19 |
-
template <typename F>
|
| 20 |
-
void cuda_mm8_one(int N, int M,
|
| 21 |
-
F *x,
|
| 22 |
-
uint8_t *w, int w_stride,
|
| 23 |
-
F *mx, F *rx,
|
| 24 |
-
F *my, F *ry,
|
| 25 |
-
float *y);
|
| 26 |
-
|
| 27 |
-
void wkv_forward(int64_t B, int64_t T, int64_t C,
|
| 28 |
-
torch::Tensor &w, torch::Tensor &u,
|
| 29 |
-
torch::Tensor &k, torch::Tensor &v, torch::Tensor &y,
|
| 30 |
-
torch::Tensor &aa, torch::Tensor &bb, torch::Tensor &pp) {
|
| 31 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(w));
|
| 32 |
-
switch (k.scalar_type()) {
|
| 33 |
-
case c10::ScalarType::Half:
|
| 34 |
-
cuda_wkv_forward(B, T, C,
|
| 35 |
-
w.data_ptr<float>(), u.data_ptr<float>(),
|
| 36 |
-
k.data_ptr<fp16>(), v.data_ptr<fp16>(), y.data_ptr<fp16>(),
|
| 37 |
-
aa.data_ptr<float>(), bb.data_ptr<float>(), pp.data_ptr<float>());
|
| 38 |
-
break;
|
| 39 |
-
case c10::ScalarType::Float:
|
| 40 |
-
cuda_wkv_forward(B, T, C,
|
| 41 |
-
w.data_ptr<float>(), u.data_ptr<float>(),
|
| 42 |
-
k.data_ptr<float>(), v.data_ptr<float>(), y.data_ptr<float>(),
|
| 43 |
-
aa.data_ptr<float>(), bb.data_ptr<float>(), pp.data_ptr<float>());
|
| 44 |
-
break;
|
| 45 |
-
default:
|
| 46 |
-
assert(false && "Only FP16 and FP32 are currently supported");
|
| 47 |
-
}
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
void mm8_seq(int64_t B, int64_t N, int64_t M,
|
| 51 |
-
torch::Tensor &x, torch::Tensor &w,
|
| 52 |
-
torch::Tensor &mx, torch::Tensor &rx,
|
| 53 |
-
torch::Tensor &my, torch::Tensor &ry,
|
| 54 |
-
torch::Tensor &y) {
|
| 55 |
-
assert(x.stride(1) == 1);
|
| 56 |
-
assert(w.stride(1) == 1);
|
| 57 |
-
assert(mx.stride(0) == 1 && rx.stride(0) == 1);
|
| 58 |
-
assert(my.stride(0) == 1 && ry.stride(0) == 1);
|
| 59 |
-
assert(y.stride(1) == 1);
|
| 60 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(w));
|
| 61 |
-
switch (x.scalar_type()) {
|
| 62 |
-
case c10::ScalarType::Half:
|
| 63 |
-
cuda_mm8_seq(
|
| 64 |
-
B, N, M,
|
| 65 |
-
x.data_ptr<fp16>(), x.stride(0),
|
| 66 |
-
w.data_ptr<uint8_t>(), w.stride(0),
|
| 67 |
-
mx.data_ptr<fp16>(), rx.data_ptr<fp16>(),
|
| 68 |
-
my.data_ptr<fp16>(), ry.data_ptr<fp16>(),
|
| 69 |
-
y.data_ptr<fp16>(), y.stride(0));
|
| 70 |
-
break;
|
| 71 |
-
case c10::ScalarType::Float:
|
| 72 |
-
cuda_mm8_seq(
|
| 73 |
-
B, N, M,
|
| 74 |
-
x.data_ptr<float>(), x.stride(0),
|
| 75 |
-
w.data_ptr<uint8_t>(), w.stride(0),
|
| 76 |
-
mx.data_ptr<float>(), rx.data_ptr<float>(),
|
| 77 |
-
my.data_ptr<float>(), ry.data_ptr<float>(),
|
| 78 |
-
y.data_ptr<float>(), y.stride(0));
|
| 79 |
-
break;
|
| 80 |
-
default:
|
| 81 |
-
assert(false && "Only FP16 and FP32 are currently supported");
|
| 82 |
-
}
|
| 83 |
-
}
|
| 84 |
-
void mm8_one(int64_t N, int64_t M,
|
| 85 |
-
torch::Tensor &x, torch::Tensor &w,
|
| 86 |
-
torch::Tensor &mx, torch::Tensor &rx,
|
| 87 |
-
torch::Tensor &my, torch::Tensor &ry,
|
| 88 |
-
torch::Tensor &y) {
|
| 89 |
-
assert(x.stride(0) == 1);
|
| 90 |
-
assert(w.stride(1) == 1);
|
| 91 |
-
assert(mx.stride(0) == 1 && rx.stride(0) == 1);
|
| 92 |
-
assert(my.stride(0) == 1 && ry.stride(0) == 1);
|
| 93 |
-
assert(y.stride(0) == 1);
|
| 94 |
-
const at::cuda::OptionalCUDAGuard device_guard(device_of(w));
|
| 95 |
-
switch (x.scalar_type()) {
|
| 96 |
-
case c10::ScalarType::Half:
|
| 97 |
-
cuda_mm8_one(
|
| 98 |
-
N, M,
|
| 99 |
-
x.data_ptr<fp16>(),
|
| 100 |
-
w.data_ptr<uint8_t>(), w.stride(0),
|
| 101 |
-
mx.data_ptr<fp16>(), rx.data_ptr<fp16>(),
|
| 102 |
-
my.data_ptr<fp16>(), ry.data_ptr<fp16>(),
|
| 103 |
-
y.data_ptr<float>());
|
| 104 |
-
break;
|
| 105 |
-
case c10::ScalarType::Float:
|
| 106 |
-
cuda_mm8_one(
|
| 107 |
-
N, M,
|
| 108 |
-
x.data_ptr<float>(),
|
| 109 |
-
w.data_ptr<uint8_t>(), w.stride(0),
|
| 110 |
-
mx.data_ptr<float>(), rx.data_ptr<float>(),
|
| 111 |
-
my.data_ptr<float>(), ry.data_ptr<float>(),
|
| 112 |
-
y.data_ptr<float>());
|
| 113 |
-
break;
|
| 114 |
-
default:
|
| 115 |
-
assert(false && "Only FP16 and FP32 are currently supported");
|
| 116 |
-
}
|
| 117 |
-
}
|
| 118 |
-
|
| 119 |
-
using torch::Tensor;
|
| 120 |
-
|
| 121 |
-
#ifndef DISABLE_CUBLAS_GEMM
|
| 122 |
-
void gemm_fp16_cublas(Tensor a, Tensor b, Tensor c);
|
| 123 |
-
#endif
|
| 124 |
-
|
| 125 |
-
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
|
| 126 |
-
m.def("wkv_forward", &wkv_forward, "wkv forward");
|
| 127 |
-
m.def("mm8_seq", &mm8_seq, "mm8 seq");
|
| 128 |
-
m.def("mm8_one", &mm8_one, "mm8 one");
|
| 129 |
-
#ifndef DISABLE_CUBLAS_GEMM
|
| 130 |
-
m.def("gemm_fp16_cublas", &gemm_fp16_cublas, "gemv fp16 cublas");
|
| 131 |
-
#endif
|
| 132 |
-
}
|
| 133 |
-
|
| 134 |
-
TORCH_LIBRARY(rwkv, m) {
|
| 135 |
-
m.def("wkv_forward", wkv_forward);
|
| 136 |
-
m.def("mm8_seq", mm8_seq);
|
| 137 |
-
m.def("mm8_one", mm8_one);
|
| 138 |
-
#ifndef DISABLE_CUBLAS_GEMM
|
| 139 |
-
m.def("gemm_fp16_cublas", gemm_fp16_cublas);
|
| 140 |
-
#endif
|
| 141 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
dist/assets/CodeHighlight-B5gv0P8p.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
html:not(.dark) pre code.hljs{display:block;overflow-x:auto;padding:1em}html:not(.dark) code.hljs{padding:3px 5px}html:not(.dark) .hljs{color:#545454}html:not(.dark) .hljs-comment,html:not(.dark) .hljs-quote{color:#696969}html:not(.dark) .hljs-deletion,html:not(.dark) .hljs-name,html:not(.dark) .hljs-regexp,html:not(.dark) .hljs-selector-class,html:not(.dark) .hljs-selector-id,html:not(.dark) .hljs-tag,html:not(.dark) .hljs-template-variable,html:not(.dark) .hljs-variable{color:#d91e18}html:not(.dark) .hljs-attribute,html:not(.dark) .hljs-built_in,html:not(.dark) .hljs-link,html:not(.dark) .hljs-literal,html:not(.dark) .hljs-meta,html:not(.dark) .hljs-number,html:not(.dark) .hljs-params,html:not(.dark) .hljs-type{color:#aa5d00}html:not(.dark) .hljs-addition,html:not(.dark) .hljs-bullet,html:not(.dark) .hljs-string,html:not(.dark) .hljs-symbol{color:green}html:not(.dark) .hljs-section,html:not(.dark) .hljs-title{color:#007faa}html:not(.dark) .hljs-keyword,html:not(.dark) .hljs-selector-tag{color:#7928a1}html:not(.dark) .hljs-emphasis{font-style:italic}html:not(.dark) .hljs-strong{font-weight:700}@media screen and (-ms-high-contrast:active){html:not(.dark) .hljs-addition,html:not(.dark) .hljs-attribute,html:not(.dark) .hljs-built_in,html:not(.dark) .hljs-bullet,html:not(.dark) .hljs-comment,html:not(.dark) .hljs-link,html:not(.dark) .hljs-literal,html:not(.dark) .hljs-meta,html:not(.dark) .hljs-number,html:not(.dark) .hljs-params,html:not(.dark) .hljs-quote,html:not(.dark) .hljs-string,html:not(.dark) .hljs-symbol,html:not(.dark) .hljs-type{color:highlight}html:not(.dark) .hljs-keyword,html:not(.dark) .hljs-selector-tag{font-weight:700}}html.dark pre code.hljs{display:block;overflow-x:auto;padding:1em}html.dark code.hljs{padding:3px 5px}html.dark .hljs{color:#f8f8f2}html.dark .hljs-comment,html.dark .hljs-quote{color:#d4d0ab}html.dark .hljs-deletion,html.dark .hljs-name,html.dark .hljs-regexp,html.dark .hljs-selector-class,html.dark .hljs-selector-id,html.dark .hljs-tag,html.dark .hljs-template-variable,html.dark .hljs-variable{color:#ffa07a}html.dark .hljs-built_in,html.dark .hljs-link,html.dark .hljs-literal,html.dark .hljs-meta,html.dark .hljs-number,html.dark .hljs-params,html.dark .hljs-type{color:#f5ab35}html.dark .hljs-attribute{color:gold}html.dark .hljs-addition,html.dark .hljs-bullet,html.dark .hljs-string,html.dark .hljs-symbol{color:#abe338}html.dark .hljs-section,html.dark .hljs-title{color:#00e0e0}html.dark .hljs-keyword,html.dark .hljs-selector-tag{color:#dcc6e0}html.dark .hljs-emphasis{font-style:italic}html.dark .hljs-strong{font-weight:700}@media screen and (-ms-high-contrast:active){html.dark .hljs-addition,html.dark .hljs-attribute,html.dark .hljs-built_in,html.dark .hljs-bullet,html.dark .hljs-comment,html.dark .hljs-link,html.dark .hljs-literal,html.dark .hljs-meta,html.dark .hljs-number,html.dark .hljs-params,html.dark .hljs-quote,html.dark .hljs-string,html.dark .hljs-symbol,html.dark .hljs-type{color:highlight}html.dark .hljs-keyword,html.dark .hljs-selector-tag{font-weight:700}}
|
dist/assets/CodeHighlight-DL4bOcf6.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
dist/assets/Input-CsAcNC8W.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
._PromptEditor_11a96_1{overflow-y:auto;scrollbar-gutter:stable;min-height:1rem;height:100%;-webkit-user-select:none;-moz-user-select:none;user-select:none}._PromptEditorInner_11a96_9{position:relative;overflow:hidden;min-height:100%}._PromptEditorInner_11a96_9>div{white-space:pre-wrap;word-break:break-all;border-radius:inherit;overflow:hidden;font-family:inherit;font-size:1rem;font-weight:400;line-height:inherit;min-width:2px}._PromptEditorInner_11a96_9>textarea{position:absolute;top:0;left:0;right:0;bottom:0;width:100%;height:100%;font-family:inherit;font-size:1rem;font-weight:400;line-height:inherit;overflow:hidden;resize:none;outline:none;border:none;background-color:transparent;color:transparent;word-break:break-all;padding:inherit;border-radius:inherit;-webkit-user-select:auto;-moz-user-select:auto;user-select:auto}._PromptEditorInner_11a96_9>textarea::-moz-selection{background-color:#7eccf953}._PromptEditorInner_11a96_9>textarea::selection{background-color:#7eccf953}._PromptEditorInner_11a96_9 *{overflow-wrap:break-word;word-break:break-all;word-spacing:0px}._promptAction_11a96_68{font-weight:600}._promptActionLeft_11a96_76,._promptActionRight_11a96_77{color:transparent}._promptActionLeft_11a96_76:before,._promptActionRight_11a96_77:after{content:"AC";color:#aaa;position:absolute;font-size:.5em;padding:.4rem 0rem .3rem .1rem;min-width:.7rem;word-break:keep-all}._promptActionRight_11a96_77:after{padding:.4rem .2rem .3rem 0rem;margin-left:-.7rem}._promptEmotion_11a96_96{font-style:italic}._promptEmotionLeft_11a96_104,._promptEmotionRight_11a96_105{color:transparent}._promptEmotionLeft_11a96_104:before,._promptEmotionRight_11a96_105:after{content:"EM";color:#aaa;position:absolute;font-size:.5em;padding:.4rem 0rem .3rem .1rem;word-break:keep-all;min-width:.7rem}._promptEmotionRight_11a96_105:after{padding:.4rem .2rem .3rem 0;margin-left:-.7rem}._promptAction_11a96_68>span::-moz-selection,._promptEmotion_11a96_96>span::-moz-selection{color:transparent!important}._promptAction_11a96_68>span::selection,._promptEmotion_11a96_96>span::selection{color:transparent!important}._PromptEditor_11a96_1._invisibleScrollbar_11a96_135::-webkit-scrollbar{width:16px;background-color:transparent}._PromptEditor_11a96_1._invisibleScrollbar_11a96_135::-webkit-scrollbar-thumb{background-color:transparent}._PromptEditor_11a96_1._invisibleScrollbar_11a96_135{scrollbar-width:thin;scrollbar-color:transparent transparent}._input-range-root_2we18_3{display:flex;align-items:center}._input-range_2we18_3{flex:1}._input-range-number_2we18_12{min-width:30px;text-align:center}._input-range-root_2we18_3 input[type=range]{-webkit-appearance:none;-moz-appearance:none;appearance:none;background:transparent;cursor:pointer;width:25rem}._input-range-root_2we18_3 input[type=range]:focus{outline:none}._input-range-root_2we18_3 input[type=range]::-webkit-slider-runnable-track{background-color:#e3e3e3;border-radius:.5rem;height:4px}._input-range-root_2we18_3 input[type=range]::-webkit-slider-thumb{-webkit-appearance:none;-moz-appearance:none;appearance:none;margin-top:-4px;background-color:gray;border-radius:.5rem;height:12px;width:12px}._input-range-root_2we18_3 input[type=range]:active::-webkit-slider-thumb{outline:3px solid #808080;outline-offset:.125rem}._input-range-root_2we18_3 input[type=range]::-moz-range-track{background-color:#e3e3e3;border-radius:.5rem;height:4px}._input-range-root_2we18_3 input[type=range]::-moz-range-thumb{background-color:gray;border:none;border-radius:.5rem;height:12px;width:12px}._input-range-root_2we18_3 input[type=range]:active::-moz-range-thumb{outline:3px solid #808080;outline-offset:.125rem}._input-text-error_2we18_79{background-color:#ffa2a2}._input-list-input_2we18_85{flex:1;width:0;height:100%;border-radius:inherit;background-color:transparent}._input-list-control_2we18_93{display:flex;gap:8px;align-items:center;width:0;flex:1}._input-list-items_2we18_101{display:flex;flex-wrap:wrap;gap:4px}._input-list-item_2we18_101{position:relative;background-color:#fff9;border-radius:4px;padding:4px 24px 4px 8px;cursor:move;transition:all .2s;overflow:hidden;border:.5px solid #666;border-radius:.5rem}._input-list-item_2we18_101:hover{background:#e0e0e0}._input-list-delete_2we18_123{position:absolute;right:4px;top:50%;transform:translateY(-50%);background:none;border:none;cursor:pointer;color:#f44}._input-list-edit_2we18_134{position:absolute;left:0;top:0;bottom:0;right:0;border:none;border-radius:4px;padding:4px 24px 4px 8px}._input-list-edit-label_2we18_145{opacity:0}._input-list-counter_2we18_149{font-size:.9em;color:#666}
|
dist/assets/Input-o9Y44Uso.js
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./CodeHighlight-DL4bOcf6.js","./index-BgL29OWw.js","./index-KkrtGIAn.css","./CodeHighlight-B5gv0P8p.css","./KatexRender-DV7TN3VL.js","./KatexRender-ByavB1Nu.css"])))=>i.map(i=>d[i]);
|
| 2 |
+
var Rt=Object.defineProperty;var He=t=>{throw TypeError(t)};var $t=(t,e,r)=>e in t?Rt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var y=(t,e,r)=>$t(t,typeof e!="symbol"?e+"":e,r),_t=(t,e,r)=>e.has(t)||He("Cannot "+r);var Ge=(t,e,r)=>e.has(t)?He("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,r);var j=(t,e,r)=>(_t(t,e,"access private method"),r);import{r as f,j as p,H as Tt,I as It,R as C,J as le,d as jt,e as Nt,n as Ct,M as Lt,y as Pt,h as _,T as V,K as At,L as zt,N as Ke,O as Bt,k as Mt,_ as rt}from"./index-BgL29OWw.js";function Ie(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var Q=Ie();function st(t){Q=t}var se={exec:()=>null};function E(t,e=""){let r=typeof t=="string"?t:t.source;const n={replace:(s,i)=>{let l=typeof i=="string"?i:i.source;return l=l.replace(A.caret,"$1"),r=r.replace(s,l),n},getRegex:()=>new RegExp(r,e)};return n}var A={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceTabs:/^\t+/,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] /,listReplaceTask:/^\[[ xX]\] +/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,unescapeTest:/&(#(?:\d+)|(?:#x[0-9A-Fa-f]+)|(?:\w+));?/ig,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:t=>new RegExp(`^( {0,3}${t})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`),hrRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`),fencesBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}(?:\`\`\`|~~~)`),headingBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}#`),htmlBeginRegex:t=>new RegExp(`^ {0,${Math.min(3,t-1)}}<(?:[a-z].*>|!--)`,"i")},Dt=/^(?:[ \t]*(?:\n|$))+/,Ot=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,qt=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,ae=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,Zt=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,je=/(?:[*+-]|\d{1,9}[.)])/,it=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,at=E(it).replace(/bull/g,je).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,"").getRegex(),Ht=E(it).replace(/bull/g,je).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),Ne=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,Gt=/^[^\n]+/,Ce=/(?!\s*\])(?:\\.|[^\[\]\\])+/,Kt=E(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace("label",Ce).replace("title",/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),Ut=E(/^( {0,3}bull)([ \t][^\n]+?)?(?:\n|$)/).replace(/bull/g,je).getRegex(),me="address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul",Le=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,Vt=E("^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))","i").replace("comment",Le).replace("tag",me).replace("attribute",/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),lt=E(Ne).replace("hr",ae).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("|table","").replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",me).getRegex(),Wt=E(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace("paragraph",lt).getRegex(),Pe={blockquote:Wt,code:Ot,def:Kt,fences:qt,heading:Zt,hr:ae,html:Vt,lheading:at,list:Ut,newline:Dt,paragraph:lt,table:se,text:Gt},Ue=E("^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)").replace("hr",ae).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("blockquote"," {0,3}>").replace("code","(?: {4}| {0,3} )[^\\n]").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",me).getRegex(),Ft={...Pe,lheading:Ht,table:Ue,paragraph:E(Ne).replace("hr",ae).replace("heading"," {0,3}#{1,6}(?:\\s|$)").replace("|lheading","").replace("table",Ue).replace("blockquote"," {0,3}>").replace("fences"," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace("list"," {0,3}(?:[*+-]|1[.)]) ").replace("html","</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)").replace("tag",me).getRegex()},Qt={...Pe,html:E(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace("comment",Le).replace(/tag/g,"(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b").getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:se,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:E(Ne).replace("hr",ae).replace("heading",` *#{1,6} *[^
|
| 3 |
+
]`).replace("lheading",at).replace("|table","").replace("blockquote"," {0,3}>").replace("|fences","").replace("|list","").replace("|html","").replace("|tag","").getRegex()},Xt=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,Jt=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,ot=/^( {2,}|\\)\n(?!\s*$)/,Yt=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,xe=/[\p{P}\p{S}]/u,Ae=/[\s\p{P}\p{S}]/u,ct=/[^\s\p{P}\p{S}]/u,en=E(/^((?![*_])punctSpace)/,"u").replace(/punctSpace/g,Ae).getRegex(),ut=/(?!~)[\p{P}\p{S}]/u,tn=/(?!~)[\s\p{P}\p{S}]/u,nn=/(?:[^\s\p{P}\p{S}]|~)/u,rn=/\[[^[\]]*?\]\((?:\\.|[^\\\(\)]|\((?:\\.|[^\\\(\)])*\))*\)|`[^`]*?`|<[^<>]*?>/g,pt=/^(?:\*+(?:((?!\*)punct)|[^\s*]))|^_+(?:((?!_)punct)|([^\s_]))/,sn=E(pt,"u").replace(/punct/g,xe).getRegex(),an=E(pt,"u").replace(/punct/g,ut).getRegex(),ht="^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)",ln=E(ht,"gu").replace(/notPunctSpace/g,ct).replace(/punctSpace/g,Ae).replace(/punct/g,xe).getRegex(),on=E(ht,"gu").replace(/notPunctSpace/g,nn).replace(/punctSpace/g,tn).replace(/punct/g,ut).getRegex(),cn=E("^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)","gu").replace(/notPunctSpace/g,ct).replace(/punctSpace/g,Ae).replace(/punct/g,xe).getRegex(),un=E(/\\(punct)/,"gu").replace(/punct/g,xe).getRegex(),pn=E(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace("scheme",/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace("email",/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),hn=E(Le).replace("(?:-->|$)","-->").getRegex(),dn=E("^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>").replace("comment",hn).replace("attribute",/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),he=/(?:\[(?:\\.|[^\[\]\\])*\]|\\.|`[^`]*`|[^\[\]\\`])*?/,fn=E(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]*(?:\n[ \t]*)?)(title))?\s*\)/).replace("label",he).replace("href",/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace("title",/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),dt=E(/^!?\[(label)\]\[(ref)\]/).replace("label",he).replace("ref",Ce).getRegex(),ft=E(/^!?\[(ref)\](?:\[\])?/).replace("ref",Ce).getRegex(),gn=E("reflink|nolink(?!\\()","g").replace("reflink",dt).replace("nolink",ft).getRegex(),ze={_backpedal:se,anyPunctuation:un,autolink:pn,blockSkip:rn,br:ot,code:Jt,del:se,emStrongLDelim:sn,emStrongRDelimAst:ln,emStrongRDelimUnd:cn,escape:Xt,link:fn,nolink:ft,punctuation:en,reflink:dt,reflinkSearch:gn,tag:dn,text:Yt,url:se},mn={...ze,link:E(/^!?\[(label)\]\((.*?)\)/).replace("label",he).getRegex(),reflink:E(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace("label",he).getRegex()},ye={...ze,emStrongRDelimAst:on,emStrongLDelim:an,url:E(/^((?:ftp|https?):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/,"i").replace("email",/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\.|[^\\])*?(?:\\.|[^\s~\\]))\1(?=[^~]|$)/,text:/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|https?:\/\/|ftp:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/},xn={...ye,br:E(ot).replace("{2,}","*").getRegex(),text:E(ye.text).replace("\\b_","\\b_| {2,}\\n").replace(/\{2,\}/g,"*").getRegex()},oe={normal:Pe,gfm:Ft,pedantic:Qt},te={normal:ze,gfm:ye,breaks:xn,pedantic:mn},kn={"&":"&","<":"<",">":">",'"':""","'":"'"},Ve=t=>kn[t];function O(t,e){if(e){if(A.escapeTest.test(t))return t.replace(A.escapeReplace,Ve)}else if(A.escapeTestNoEncode.test(t))return t.replace(A.escapeReplaceNoEncode,Ve);return t}function We(t){try{t=encodeURI(t).replace(A.percentDecode,"%")}catch{return null}return t}function Fe(t,e){var i;const r=t.replace(A.findPipe,(l,a,c)=>{let o=!1,u=a;for(;--u>=0&&c[u]==="\\";)o=!o;return o?"|":" |"}),n=r.split(A.splitPipe);let s=0;if(n[0].trim()||n.shift(),n.length>0&&!((i=n.at(-1))!=null&&i.trim())&&n.pop(),e)if(n.length>e)n.splice(e);else for(;n.length<e;)n.push("");for(;s<n.length;s++)n[s]=n[s].trim().replace(A.slashPipe,"|");return n}function ne(t,e,r){const n=t.length;if(n===0)return"";let s=0;for(;s<n&&t.charAt(n-s-1)===e;)s++;return t.slice(0,n-s)}function bn(t,e){if(t.indexOf(e[1])===-1)return-1;let r=0;for(let n=0;n<t.length;n++)if(t[n]==="\\")n++;else if(t[n]===e[0])r++;else if(t[n]===e[1]&&(r--,r<0))return n;return r>0?-2:-1}function Qe(t,e,r,n,s){const i=e.href,l=e.title||null,a=t[1].replace(s.other.outputLinkReplace,"$1");n.state.inLink=!0;const c={type:t[0].charAt(0)==="!"?"image":"link",raw:r,href:i,title:l,text:a,tokens:n.inlineTokens(a)};return n.state.inLink=!1,c}function wn(t,e,r){const n=t.match(r.other.indentCodeCompensation);if(n===null)return e;const s=n[1];return e.split(`
|
| 4 |
+
`).map(i=>{const l=i.match(r.other.beginningSpace);if(l===null)return i;const[a]=l;return a.length>=s.length?i.slice(s.length):i}).join(`
|
| 5 |
+
`)}var de=class{constructor(t){y(this,"options");y(this,"rules");y(this,"lexer");this.options=t||Q}space(t){const e=this.rules.block.newline.exec(t);if(e&&e[0].length>0)return{type:"space",raw:e[0]}}code(t){const e=this.rules.block.code.exec(t);if(e){const r=e[0].replace(this.rules.other.codeRemoveIndent,"");return{type:"code",raw:e[0],codeBlockStyle:"indented",text:this.options.pedantic?r:ne(r,`
|
| 6 |
+
`)}}}fences(t){const e=this.rules.block.fences.exec(t);if(e){const r=e[0],n=wn(r,e[3]||"",this.rules);return{type:"code",raw:r,lang:e[2]?e[2].trim().replace(this.rules.inline.anyPunctuation,"$1"):e[2],text:n}}}heading(t){const e=this.rules.block.heading.exec(t);if(e){let r=e[2].trim();if(this.rules.other.endingHash.test(r)){const n=ne(r,"#");(this.options.pedantic||!n||this.rules.other.endingSpaceChar.test(n))&&(r=n.trim())}return{type:"heading",raw:e[0],depth:e[1].length,text:r,tokens:this.lexer.inline(r)}}}hr(t){const e=this.rules.block.hr.exec(t);if(e)return{type:"hr",raw:ne(e[0],`
|
| 7 |
+
`)}}blockquote(t){const e=this.rules.block.blockquote.exec(t);if(e){let r=ne(e[0],`
|
| 8 |
+
`).split(`
|
| 9 |
+
`),n="",s="";const i=[];for(;r.length>0;){let l=!1;const a=[];let c;for(c=0;c<r.length;c++)if(this.rules.other.blockquoteStart.test(r[c]))a.push(r[c]),l=!0;else if(!l)a.push(r[c]);else break;r=r.slice(c);const o=a.join(`
|
| 10 |
+
`),u=o.replace(this.rules.other.blockquoteSetextReplace,`
|
| 11 |
+
$1`).replace(this.rules.other.blockquoteSetextReplace2,"");n=n?`${n}
|
| 12 |
+
${o}`:o,s=s?`${s}
|
| 13 |
+
${u}`:u;const d=this.lexer.state.top;if(this.lexer.state.top=!0,this.lexer.blockTokens(u,i,!0),this.lexer.state.top=d,r.length===0)break;const h=i.at(-1);if((h==null?void 0:h.type)==="code")break;if((h==null?void 0:h.type)==="blockquote"){const g=h,x=g.raw+`
|
| 14 |
+
`+r.join(`
|
| 15 |
+
`),S=this.blockquote(x);i[i.length-1]=S,n=n.substring(0,n.length-g.raw.length)+S.raw,s=s.substring(0,s.length-g.text.length)+S.text;break}else if((h==null?void 0:h.type)==="list"){const g=h,x=g.raw+`
|
| 16 |
+
`+r.join(`
|
| 17 |
+
`),S=this.list(x);i[i.length-1]=S,n=n.substring(0,n.length-h.raw.length)+S.raw,s=s.substring(0,s.length-g.raw.length)+S.raw,r=x.substring(i.at(-1).raw.length).split(`
|
| 18 |
+
`);continue}}return{type:"blockquote",raw:n,tokens:i,text:s}}}list(t){let e=this.rules.block.list.exec(t);if(e){let r=e[1].trim();const n=r.length>1,s={type:"list",raw:"",ordered:n,start:n?+r.slice(0,-1):"",loose:!1,items:[]};r=n?`\\d{1,9}\\${r.slice(-1)}`:`\\${r}`,this.options.pedantic&&(r=n?r:"[*+-]");const i=this.rules.other.listItemRegex(r);let l=!1;for(;t;){let c=!1,o="",u="";if(!(e=i.exec(t))||this.rules.block.hr.test(t))break;o=e[0],t=t.substring(o.length);let d=e[2].split(`
|
| 19 |
+
`,1)[0].replace(this.rules.other.listReplaceTabs,m=>" ".repeat(3*m.length)),h=t.split(`
|
| 20 |
+
`,1)[0],g=!d.trim(),x=0;if(this.options.pedantic?(x=2,u=d.trimStart()):g?x=e[1].length+1:(x=e[2].search(this.rules.other.nonSpaceChar),x=x>4?1:x,u=d.slice(x),x+=e[1].length),g&&this.rules.other.blankLine.test(h)&&(o+=h+`
|
| 21 |
+
`,t=t.substring(h.length+1),c=!0),!c){const m=this.rules.other.nextBulletRegex(x),w=this.rules.other.hrRegex(x),I=this.rules.other.fencesBeginRegex(x),k=this.rules.other.headingBeginRegex(x),v=this.rules.other.htmlBeginRegex(x);for(;t;){const L=t.split(`
|
| 22 |
+
`,1)[0];let b;if(h=L,this.options.pedantic?(h=h.replace(this.rules.other.listReplaceNesting," "),b=h):b=h.replace(this.rules.other.tabCharGlobal," "),I.test(h)||k.test(h)||v.test(h)||m.test(h)||w.test(h))break;if(b.search(this.rules.other.nonSpaceChar)>=x||!h.trim())u+=`
|
| 23 |
+
`+b.slice(x);else{if(g||d.replace(this.rules.other.tabCharGlobal," ").search(this.rules.other.nonSpaceChar)>=4||I.test(d)||k.test(d)||w.test(d))break;u+=`
|
| 24 |
+
`+h}!g&&!h.trim()&&(g=!0),o+=L+`
|
| 25 |
+
`,t=t.substring(L.length+1),d=b.slice(x)}}s.loose||(l?s.loose=!0:this.rules.other.doubleBlankLine.test(o)&&(l=!0));let S=null,T;this.options.gfm&&(S=this.rules.other.listIsTask.exec(u),S&&(T=S[0]!=="[ ] ",u=u.replace(this.rules.other.listReplaceTask,""))),s.items.push({type:"list_item",raw:o,task:!!S,checked:T,loose:!1,text:u,tokens:[]}),s.raw+=o}const a=s.items.at(-1);if(a)a.raw=a.raw.trimEnd(),a.text=a.text.trimEnd();else return;s.raw=s.raw.trimEnd();for(let c=0;c<s.items.length;c++)if(this.lexer.state.top=!1,s.items[c].tokens=this.lexer.blockTokens(s.items[c].text,[]),!s.loose){const o=s.items[c].tokens.filter(d=>d.type==="space"),u=o.length>0&&o.some(d=>this.rules.other.anyLine.test(d.raw));s.loose=u}if(s.loose)for(let c=0;c<s.items.length;c++)s.items[c].loose=!0;return s}}html(t){const e=this.rules.block.html.exec(t);if(e)return{type:"html",block:!0,raw:e[0],pre:e[1]==="pre"||e[1]==="script"||e[1]==="style",text:e[0]}}def(t){const e=this.rules.block.def.exec(t);if(e){const r=e[1].toLowerCase().replace(this.rules.other.multipleSpaceGlobal," "),n=e[2]?e[2].replace(this.rules.other.hrefBrackets,"$1").replace(this.rules.inline.anyPunctuation,"$1"):"",s=e[3]?e[3].substring(1,e[3].length-1).replace(this.rules.inline.anyPunctuation,"$1"):e[3];return{type:"def",tag:r,raw:e[0],href:n,title:s}}}table(t){var l;const e=this.rules.block.table.exec(t);if(!e||!this.rules.other.tableDelimiter.test(e[2]))return;const r=Fe(e[1]),n=e[2].replace(this.rules.other.tableAlignChars,"").split("|"),s=(l=e[3])!=null&&l.trim()?e[3].replace(this.rules.other.tableRowBlankLine,"").split(`
|
| 26 |
+
`):[],i={type:"table",raw:e[0],header:[],align:[],rows:[]};if(r.length===n.length){for(const a of n)this.rules.other.tableAlignRight.test(a)?i.align.push("right"):this.rules.other.tableAlignCenter.test(a)?i.align.push("center"):this.rules.other.tableAlignLeft.test(a)?i.align.push("left"):i.align.push(null);for(let a=0;a<r.length;a++)i.header.push({text:r[a],tokens:this.lexer.inline(r[a]),header:!0,align:i.align[a]});for(const a of s)i.rows.push(Fe(a,i.header.length).map((c,o)=>({text:c,tokens:this.lexer.inline(c),header:!1,align:i.align[o]})));return i}}lheading(t){const e=this.rules.block.lheading.exec(t);if(e)return{type:"heading",raw:e[0],depth:e[2].charAt(0)==="="?1:2,text:e[1],tokens:this.lexer.inline(e[1])}}paragraph(t){const e=this.rules.block.paragraph.exec(t);if(e){const r=e[1].charAt(e[1].length-1)===`
|
| 27 |
+
`?e[1].slice(0,-1):e[1];return{type:"paragraph",raw:e[0],text:r,tokens:this.lexer.inline(r)}}}text(t){const e=this.rules.block.text.exec(t);if(e)return{type:"text",raw:e[0],text:e[0],tokens:this.lexer.inline(e[0])}}escape(t){const e=this.rules.inline.escape.exec(t);if(e)return{type:"escape",raw:e[0],text:e[1]}}tag(t){const e=this.rules.inline.tag.exec(t);if(e)return!this.lexer.state.inLink&&this.rules.other.startATag.test(e[0])?this.lexer.state.inLink=!0:this.lexer.state.inLink&&this.rules.other.endATag.test(e[0])&&(this.lexer.state.inLink=!1),!this.lexer.state.inRawBlock&&this.rules.other.startPreScriptTag.test(e[0])?this.lexer.state.inRawBlock=!0:this.lexer.state.inRawBlock&&this.rules.other.endPreScriptTag.test(e[0])&&(this.lexer.state.inRawBlock=!1),{type:"html",raw:e[0],inLink:this.lexer.state.inLink,inRawBlock:this.lexer.state.inRawBlock,block:!1,text:e[0]}}link(t){const e=this.rules.inline.link.exec(t);if(e){const r=e[2].trim();if(!this.options.pedantic&&this.rules.other.startAngleBracket.test(r)){if(!this.rules.other.endAngleBracket.test(r))return;const i=ne(r.slice(0,-1),"\\");if((r.length-i.length)%2===0)return}else{const i=bn(e[2],"()");if(i===-2)return;if(i>-1){const a=(e[0].indexOf("!")===0?5:4)+e[1].length+i;e[2]=e[2].substring(0,i),e[0]=e[0].substring(0,a).trim(),e[3]=""}}let n=e[2],s="";if(this.options.pedantic){const i=this.rules.other.pedanticHrefTitle.exec(n);i&&(n=i[1],s=i[3])}else s=e[3]?e[3].slice(1,-1):"";return n=n.trim(),this.rules.other.startAngleBracket.test(n)&&(this.options.pedantic&&!this.rules.other.endAngleBracket.test(r)?n=n.slice(1):n=n.slice(1,-1)),Qe(e,{href:n&&n.replace(this.rules.inline.anyPunctuation,"$1"),title:s&&s.replace(this.rules.inline.anyPunctuation,"$1")},e[0],this.lexer,this.rules)}}reflink(t,e){let r;if((r=this.rules.inline.reflink.exec(t))||(r=this.rules.inline.nolink.exec(t))){const n=(r[2]||r[1]).replace(this.rules.other.multipleSpaceGlobal," "),s=e[n.toLowerCase()];if(!s){const i=r[0].charAt(0);return{type:"text",raw:i,text:i}}return Qe(r,s,r[0],this.lexer,this.rules)}}emStrong(t,e,r=""){let n=this.rules.inline.emStrongLDelim.exec(t);if(!n||n[3]&&r.match(this.rules.other.unicodeAlphaNumeric))return;if(!(n[1]||n[2]||"")||!r||this.rules.inline.punctuation.exec(r)){const i=[...n[0]].length-1;let l,a,c=i,o=0;const u=n[0][0]==="*"?this.rules.inline.emStrongRDelimAst:this.rules.inline.emStrongRDelimUnd;for(u.lastIndex=0,e=e.slice(-1*t.length+i);(n=u.exec(e))!=null;){if(l=n[1]||n[2]||n[3]||n[4]||n[5]||n[6],!l)continue;if(a=[...l].length,n[3]||n[4]){c+=a;continue}else if((n[5]||n[6])&&i%3&&!((i+a)%3)){o+=a;continue}if(c-=a,c>0)continue;a=Math.min(a,a+c+o);const d=[...n[0]][0].length,h=t.slice(0,i+n.index+d+a);if(Math.min(i,a)%2){const x=h.slice(1,-1);return{type:"em",raw:h,text:x,tokens:this.lexer.inlineTokens(x)}}const g=h.slice(2,-2);return{type:"strong",raw:h,text:g,tokens:this.lexer.inlineTokens(g)}}}}codespan(t){const e=this.rules.inline.code.exec(t);if(e){let r=e[2].replace(this.rules.other.newLineCharGlobal," ");const n=this.rules.other.nonSpaceChar.test(r),s=this.rules.other.startingSpaceChar.test(r)&&this.rules.other.endingSpaceChar.test(r);return n&&s&&(r=r.substring(1,r.length-1)),{type:"codespan",raw:e[0],text:r}}}br(t){const e=this.rules.inline.br.exec(t);if(e)return{type:"br",raw:e[0]}}del(t){const e=this.rules.inline.del.exec(t);if(e)return{type:"del",raw:e[0],text:e[2],tokens:this.lexer.inlineTokens(e[2])}}autolink(t){const e=this.rules.inline.autolink.exec(t);if(e){let r,n;return e[2]==="@"?(r=e[1],n="mailto:"+r):(r=e[1],n=r),{type:"link",raw:e[0],text:r,href:n,tokens:[{type:"text",raw:r,text:r}]}}}url(t){var r;let e;if(e=this.rules.inline.url.exec(t)){let n,s;if(e[2]==="@")n=e[0],s="mailto:"+n;else{let i;do i=e[0],e[0]=((r=this.rules.inline._backpedal.exec(e[0]))==null?void 0:r[0])??"";while(i!==e[0]);n=e[0],e[1]==="www."?s="http://"+e[0]:s=e[0]}return{type:"link",raw:e[0],text:n,href:s,tokens:[{type:"text",raw:n,text:n}]}}}inlineText(t){const e=this.rules.inline.text.exec(t);if(e){const r=this.lexer.state.inRawBlock;return{type:"text",raw:e[0],text:e[0],escaped:r}}}},H=class Ee{constructor(e){y(this,"tokens");y(this,"options");y(this,"state");y(this,"tokenizer");y(this,"inlineQueue");this.tokens=[],this.tokens.links=Object.create(null),this.options=e||Q,this.options.tokenizer=this.options.tokenizer||new de,this.tokenizer=this.options.tokenizer,this.tokenizer.options=this.options,this.tokenizer.lexer=this,this.inlineQueue=[],this.state={inLink:!1,inRawBlock:!1,top:!0};const r={other:A,block:oe.normal,inline:te.normal};this.options.pedantic?(r.block=oe.pedantic,r.inline=te.pedantic):this.options.gfm&&(r.block=oe.gfm,this.options.breaks?r.inline=te.breaks:r.inline=te.gfm),this.tokenizer.rules=r}static get rules(){return{block:oe,inline:te}}static lex(e,r){return new Ee(r).lex(e)}static lexInline(e,r){return new Ee(r).inlineTokens(e)}lex(e){e=e.replace(A.carriageReturn,`
|
| 28 |
+
`),this.blockTokens(e,this.tokens);for(let r=0;r<this.inlineQueue.length;r++){const n=this.inlineQueue[r];this.inlineTokens(n.src,n.tokens)}return this.inlineQueue=[],this.tokens}blockTokens(e,r=[],n=!1){var s,i,l;for(this.options.pedantic&&(e=e.replace(A.tabCharGlobal," ").replace(A.spaceLine,""));e;){let a;if((i=(s=this.options.extensions)==null?void 0:s.block)!=null&&i.some(o=>(a=o.call({lexer:this},e,r))?(e=e.substring(a.raw.length),r.push(a),!0):!1))continue;if(a=this.tokenizer.space(e)){e=e.substring(a.raw.length);const o=r.at(-1);a.raw.length===1&&o!==void 0?o.raw+=`
|
| 29 |
+
`:r.push(a);continue}if(a=this.tokenizer.code(e)){e=e.substring(a.raw.length);const o=r.at(-1);(o==null?void 0:o.type)==="paragraph"||(o==null?void 0:o.type)==="text"?(o.raw+=`
|
| 30 |
+
`+a.raw,o.text+=`
|
| 31 |
+
`+a.text,this.inlineQueue.at(-1).src=o.text):r.push(a);continue}if(a=this.tokenizer.fences(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.heading(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.hr(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.blockquote(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.list(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.html(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.def(e)){e=e.substring(a.raw.length);const o=r.at(-1);(o==null?void 0:o.type)==="paragraph"||(o==null?void 0:o.type)==="text"?(o.raw+=`
|
| 32 |
+
`+a.raw,o.text+=`
|
| 33 |
+
`+a.raw,this.inlineQueue.at(-1).src=o.text):this.tokens.links[a.tag]||(this.tokens.links[a.tag]={href:a.href,title:a.title});continue}if(a=this.tokenizer.table(e)){e=e.substring(a.raw.length),r.push(a);continue}if(a=this.tokenizer.lheading(e)){e=e.substring(a.raw.length),r.push(a);continue}let c=e;if((l=this.options.extensions)!=null&&l.startBlock){let o=1/0;const u=e.slice(1);let d;this.options.extensions.startBlock.forEach(h=>{d=h.call({lexer:this},u),typeof d=="number"&&d>=0&&(o=Math.min(o,d))}),o<1/0&&o>=0&&(c=e.substring(0,o+1))}if(this.state.top&&(a=this.tokenizer.paragraph(c))){const o=r.at(-1);n&&(o==null?void 0:o.type)==="paragraph"?(o.raw+=`
|
| 34 |
+
`+a.raw,o.text+=`
|
| 35 |
+
`+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):r.push(a),n=c.length!==e.length,e=e.substring(a.raw.length);continue}if(a=this.tokenizer.text(e)){e=e.substring(a.raw.length);const o=r.at(-1);(o==null?void 0:o.type)==="text"?(o.raw+=`
|
| 36 |
+
`+a.raw,o.text+=`
|
| 37 |
+
`+a.text,this.inlineQueue.pop(),this.inlineQueue.at(-1).src=o.text):r.push(a);continue}if(e){const o="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(o);break}else throw new Error(o)}}return this.state.top=!0,r}inline(e,r=[]){return this.inlineQueue.push({src:e,tokens:r}),r}inlineTokens(e,r=[]){var a,c,o;let n=e,s=null;if(this.tokens.links){const u=Object.keys(this.tokens.links);if(u.length>0)for(;(s=this.tokenizer.rules.inline.reflinkSearch.exec(n))!=null;)u.includes(s[0].slice(s[0].lastIndexOf("[")+1,-1))&&(n=n.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.reflinkSearch.lastIndex))}for(;(s=this.tokenizer.rules.inline.anyPunctuation.exec(n))!=null;)n=n.slice(0,s.index)+"++"+n.slice(this.tokenizer.rules.inline.anyPunctuation.lastIndex);for(;(s=this.tokenizer.rules.inline.blockSkip.exec(n))!=null;)n=n.slice(0,s.index)+"["+"a".repeat(s[0].length-2)+"]"+n.slice(this.tokenizer.rules.inline.blockSkip.lastIndex);let i=!1,l="";for(;e;){i||(l=""),i=!1;let u;if((c=(a=this.options.extensions)==null?void 0:a.inline)!=null&&c.some(h=>(u=h.call({lexer:this},e,r))?(e=e.substring(u.raw.length),r.push(u),!0):!1))continue;if(u=this.tokenizer.escape(e)){e=e.substring(u.raw.length),r.push(u);continue}if(u=this.tokenizer.tag(e)){e=e.substring(u.raw.length),r.push(u);continue}if(u=this.tokenizer.link(e)){e=e.substring(u.raw.length),r.push(u);continue}if(u=this.tokenizer.reflink(e,this.tokens.links)){e=e.substring(u.raw.length);const h=r.at(-1);u.type==="text"&&(h==null?void 0:h.type)==="text"?(h.raw+=u.raw,h.text+=u.text):r.push(u);continue}if(u=this.tokenizer.emStrong(e,n,l)){e=e.substring(u.raw.length),r.push(u);continue}if(u=this.tokenizer.codespan(e)){e=e.substring(u.raw.length),r.push(u);continue}if(u=this.tokenizer.br(e)){e=e.substring(u.raw.length),r.push(u);continue}if(u=this.tokenizer.del(e)){e=e.substring(u.raw.length),r.push(u);continue}if(u=this.tokenizer.autolink(e)){e=e.substring(u.raw.length),r.push(u);continue}if(!this.state.inLink&&(u=this.tokenizer.url(e))){e=e.substring(u.raw.length),r.push(u);continue}let d=e;if((o=this.options.extensions)!=null&&o.startInline){let h=1/0;const g=e.slice(1);let x;this.options.extensions.startInline.forEach(S=>{x=S.call({lexer:this},g),typeof x=="number"&&x>=0&&(h=Math.min(h,x))}),h<1/0&&h>=0&&(d=e.substring(0,h+1))}if(u=this.tokenizer.inlineText(d)){e=e.substring(u.raw.length),u.raw.slice(-1)!=="_"&&(l=u.raw.slice(-1)),i=!0;const h=r.at(-1);(h==null?void 0:h.type)==="text"?(h.raw+=u.raw,h.text+=u.text):r.push(u);continue}if(e){const h="Infinite loop on byte: "+e.charCodeAt(0);if(this.options.silent){console.error(h);break}else throw new Error(h)}}return r}},fe=class{constructor(t){y(this,"options");y(this,"parser");this.options=t||Q}space(t){return""}code({text:t,lang:e,escaped:r}){var i;const n=(i=(e||"").match(A.notSpaceStart))==null?void 0:i[0],s=t.replace(A.endingNewline,"")+`
|
| 38 |
+
`;return n?'<pre><code class="language-'+O(n)+'">'+(r?s:O(s,!0))+`</code></pre>
|
| 39 |
+
`:"<pre><code>"+(r?s:O(s,!0))+`</code></pre>
|
| 40 |
+
`}blockquote({tokens:t}){return`<blockquote>
|
| 41 |
+
${this.parser.parse(t)}</blockquote>
|
| 42 |
+
`}html({text:t}){return t}heading({tokens:t,depth:e}){return`<h${e}>${this.parser.parseInline(t)}</h${e}>
|
| 43 |
+
`}hr(t){return`<hr>
|
| 44 |
+
`}list(t){const e=t.ordered,r=t.start;let n="";for(let l=0;l<t.items.length;l++){const a=t.items[l];n+=this.listitem(a)}const s=e?"ol":"ul",i=e&&r!==1?' start="'+r+'"':"";return"<"+s+i+`>
|
| 45 |
+
`+n+"</"+s+`>
|
| 46 |
+
`}listitem(t){var r;let e="";if(t.task){const n=this.checkbox({checked:!!t.checked});t.loose?((r=t.tokens[0])==null?void 0:r.type)==="paragraph"?(t.tokens[0].text=n+" "+t.tokens[0].text,t.tokens[0].tokens&&t.tokens[0].tokens.length>0&&t.tokens[0].tokens[0].type==="text"&&(t.tokens[0].tokens[0].text=n+" "+O(t.tokens[0].tokens[0].text),t.tokens[0].tokens[0].escaped=!0)):t.tokens.unshift({type:"text",raw:n+" ",text:n+" ",escaped:!0}):e+=n+" "}return e+=this.parser.parse(t.tokens,!!t.loose),`<li>${e}</li>
|
| 47 |
+
`}checkbox({checked:t}){return"<input "+(t?'checked="" ':"")+'disabled="" type="checkbox">'}paragraph({tokens:t}){return`<p>${this.parser.parseInline(t)}</p>
|
| 48 |
+
`}table(t){let e="",r="";for(let s=0;s<t.header.length;s++)r+=this.tablecell(t.header[s]);e+=this.tablerow({text:r});let n="";for(let s=0;s<t.rows.length;s++){const i=t.rows[s];r="";for(let l=0;l<i.length;l++)r+=this.tablecell(i[l]);n+=this.tablerow({text:r})}return n&&(n=`<tbody>${n}</tbody>`),`<table>
|
| 49 |
+
<thead>
|
| 50 |
+
`+e+`</thead>
|
| 51 |
+
`+n+`</table>
|
| 52 |
+
`}tablerow({text:t}){return`<tr>
|
| 53 |
+
${t}</tr>
|
| 54 |
+
`}tablecell(t){const e=this.parser.parseInline(t.tokens),r=t.header?"th":"td";return(t.align?`<${r} align="${t.align}">`:`<${r}>`)+e+`</${r}>
|
| 55 |
+
`}strong({tokens:t}){return`<strong>${this.parser.parseInline(t)}</strong>`}em({tokens:t}){return`<em>${this.parser.parseInline(t)}</em>`}codespan({text:t}){return`<code>${O(t,!0)}</code>`}br(t){return"<br>"}del({tokens:t}){return`<del>${this.parser.parseInline(t)}</del>`}link({href:t,title:e,tokens:r}){const n=this.parser.parseInline(r),s=We(t);if(s===null)return n;t=s;let i='<a href="'+t+'"';return e&&(i+=' title="'+O(e)+'"'),i+=">"+n+"</a>",i}image({href:t,title:e,text:r,tokens:n}){n&&(r=this.parser.parseInline(n,this.parser.textRenderer));const s=We(t);if(s===null)return O(r);t=s;let i=`<img src="${t}" alt="${r}"`;return e&&(i+=` title="${O(e)}"`),i+=">",i}text(t){return"tokens"in t&&t.tokens?this.parser.parseInline(t.tokens):"escaped"in t&&t.escaped?t.text:O(t.text)}},Be=class{strong({text:t}){return t}em({text:t}){return t}codespan({text:t}){return t}del({text:t}){return t}html({text:t}){return t}text({text:t}){return t}link({text:t}){return""+t}image({text:t}){return""+t}br(){return""}},G=class Se{constructor(e){y(this,"options");y(this,"renderer");y(this,"textRenderer");this.options=e||Q,this.options.renderer=this.options.renderer||new fe,this.renderer=this.options.renderer,this.renderer.options=this.options,this.renderer.parser=this,this.textRenderer=new Be}static parse(e,r){return new Se(r).parse(e)}static parseInline(e,r){return new Se(r).parseInline(e)}parse(e,r=!0){var s,i;let n="";for(let l=0;l<e.length;l++){const a=e[l];if((i=(s=this.options.extensions)==null?void 0:s.renderers)!=null&&i[a.type]){const o=a,u=this.options.extensions.renderers[o.type].call({parser:this},o);if(u!==!1||!["space","hr","heading","code","table","blockquote","list","html","paragraph","text"].includes(o.type)){n+=u||"";continue}}const c=a;switch(c.type){case"space":{n+=this.renderer.space(c);continue}case"hr":{n+=this.renderer.hr(c);continue}case"heading":{n+=this.renderer.heading(c);continue}case"code":{n+=this.renderer.code(c);continue}case"table":{n+=this.renderer.table(c);continue}case"blockquote":{n+=this.renderer.blockquote(c);continue}case"list":{n+=this.renderer.list(c);continue}case"html":{n+=this.renderer.html(c);continue}case"paragraph":{n+=this.renderer.paragraph(c);continue}case"text":{let o=c,u=this.renderer.text(o);for(;l+1<e.length&&e[l+1].type==="text";)o=e[++l],u+=`
|
| 56 |
+
`+this.renderer.text(o);r?n+=this.renderer.paragraph({type:"paragraph",raw:u,text:u,tokens:[{type:"text",raw:u,text:u,escaped:!0}]}):n+=u;continue}default:{const o='Token with "'+c.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}parseInline(e,r=this.renderer){var s,i;let n="";for(let l=0;l<e.length;l++){const a=e[l];if((i=(s=this.options.extensions)==null?void 0:s.renderers)!=null&&i[a.type]){const o=this.options.extensions.renderers[a.type].call({parser:this},a);if(o!==!1||!["escape","html","link","image","strong","em","codespan","br","del","text"].includes(a.type)){n+=o||"";continue}}const c=a;switch(c.type){case"escape":{n+=r.text(c);break}case"html":{n+=r.html(c);break}case"link":{n+=r.link(c);break}case"image":{n+=r.image(c);break}case"strong":{n+=r.strong(c);break}case"em":{n+=r.em(c);break}case"codespan":{n+=r.codespan(c);break}case"br":{n+=r.br(c);break}case"del":{n+=r.del(c);break}case"text":{n+=r.text(c);break}default:{const o='Token with "'+c.type+'" type was not found.';if(this.options.silent)return console.error(o),"";throw new Error(o)}}}return n}},ve,pe=(ve=class{constructor(t){y(this,"options");y(this,"block");this.options=t||Q}preprocess(t){return t}postprocess(t){return t}processAllTokens(t){return t}provideLexer(){return this.block?H.lex:H.lexInline}provideParser(){return this.block?G.parse:G.parseInline}},y(ve,"passThroughHooks",new Set(["preprocess","postprocess","processAllTokens"])),ve),gt=class{constructor(...t){y(this,"defaults",Ie());y(this,"options",this.setOptions);y(this,"parse",this.parseMarkdown(!0));y(this,"parseInline",this.parseMarkdown(!1));y(this,"Parser",G);y(this,"Renderer",fe);y(this,"TextRenderer",Be);y(this,"Lexer",H);y(this,"Tokenizer",de);y(this,"Hooks",pe);this.use(...t)}walkTokens(t,e){var n,s;let r=[];for(const i of t)switch(r=r.concat(e.call(this,i)),i.type){case"table":{const l=i;for(const a of l.header)r=r.concat(this.walkTokens(a.tokens,e));for(const a of l.rows)for(const c of a)r=r.concat(this.walkTokens(c.tokens,e));break}case"list":{const l=i;r=r.concat(this.walkTokens(l.items,e));break}default:{const l=i;(s=(n=this.defaults.extensions)==null?void 0:n.childTokens)!=null&&s[l.type]?this.defaults.extensions.childTokens[l.type].forEach(a=>{const c=l[a].flat(1/0);r=r.concat(this.walkTokens(c,e))}):l.tokens&&(r=r.concat(this.walkTokens(l.tokens,e)))}}return r}use(...t){const e=this.defaults.extensions||{renderers:{},childTokens:{}};return t.forEach(r=>{const n={...r};if(n.async=this.defaults.async||n.async||!1,r.extensions&&(r.extensions.forEach(s=>{if(!s.name)throw new Error("extension name required");if("renderer"in s){const i=e.renderers[s.name];i?e.renderers[s.name]=function(...l){let a=s.renderer.apply(this,l);return a===!1&&(a=i.apply(this,l)),a}:e.renderers[s.name]=s.renderer}if("tokenizer"in s){if(!s.level||s.level!=="block"&&s.level!=="inline")throw new Error("extension level must be 'block' or 'inline'");const i=e[s.level];i?i.unshift(s.tokenizer):e[s.level]=[s.tokenizer],s.start&&(s.level==="block"?e.startBlock?e.startBlock.push(s.start):e.startBlock=[s.start]:s.level==="inline"&&(e.startInline?e.startInline.push(s.start):e.startInline=[s.start]))}"childTokens"in s&&s.childTokens&&(e.childTokens[s.name]=s.childTokens)}),n.extensions=e),r.renderer){const s=this.defaults.renderer||new fe(this.defaults);for(const i in r.renderer){if(!(i in s))throw new Error(`renderer '${i}' does not exist`);if(["options","parser"].includes(i))continue;const l=i,a=r.renderer[l],c=s[l];s[l]=(...o)=>{let u=a.apply(s,o);return u===!1&&(u=c.apply(s,o)),u||""}}n.renderer=s}if(r.tokenizer){const s=this.defaults.tokenizer||new de(this.defaults);for(const i in r.tokenizer){if(!(i in s))throw new Error(`tokenizer '${i}' does not exist`);if(["options","rules","lexer"].includes(i))continue;const l=i,a=r.tokenizer[l],c=s[l];s[l]=(...o)=>{let u=a.apply(s,o);return u===!1&&(u=c.apply(s,o)),u}}n.tokenizer=s}if(r.hooks){const s=this.defaults.hooks||new pe;for(const i in r.hooks){if(!(i in s))throw new Error(`hook '${i}' does not exist`);if(["options","block"].includes(i))continue;const l=i,a=r.hooks[l],c=s[l];pe.passThroughHooks.has(i)?s[l]=o=>{if(this.defaults.async)return Promise.resolve(a.call(s,o)).then(d=>c.call(s,d));const u=a.call(s,o);return c.call(s,u)}:s[l]=(...o)=>{let u=a.apply(s,o);return u===!1&&(u=c.apply(s,o)),u}}n.hooks=s}if(r.walkTokens){const s=this.defaults.walkTokens,i=r.walkTokens;n.walkTokens=function(l){let a=[];return a.push(i.call(this,l)),s&&(a=a.concat(s.call(this,l))),a}}this.defaults={...this.defaults,...n}}),this}setOptions(t){return this.defaults={...this.defaults,...t},this}lexer(t,e){return H.lex(t,e??this.defaults)}parser(t,e){return G.parse(t,e??this.defaults)}parseMarkdown(t){return(r,n)=>{const s={...n},i={...this.defaults,...s},l=this.onError(!!i.silent,!!i.async);if(this.defaults.async===!0&&s.async===!1)return l(new Error("marked(): The async option was set to true by an extension. Remove async: false from the parse options object to return a Promise."));if(typeof r>"u"||r===null)return l(new Error("marked(): input parameter is undefined or null"));if(typeof r!="string")return l(new Error("marked(): input parameter is of type "+Object.prototype.toString.call(r)+", string expected"));i.hooks&&(i.hooks.options=i,i.hooks.block=t);const a=i.hooks?i.hooks.provideLexer():t?H.lex:H.lexInline,c=i.hooks?i.hooks.provideParser():t?G.parse:G.parseInline;if(i.async)return Promise.resolve(i.hooks?i.hooks.preprocess(r):r).then(o=>a(o,i)).then(o=>i.hooks?i.hooks.processAllTokens(o):o).then(o=>i.walkTokens?Promise.all(this.walkTokens(o,i.walkTokens)).then(()=>o):o).then(o=>c(o,i)).then(o=>i.hooks?i.hooks.postprocess(o):o).catch(l);try{i.hooks&&(r=i.hooks.preprocess(r));let o=a(r,i);i.hooks&&(o=i.hooks.processAllTokens(o)),i.walkTokens&&this.walkTokens(o,i.walkTokens);let u=c(o,i);return i.hooks&&(u=i.hooks.postprocess(u)),u}catch(o){return l(o)}}}onError(t,e){return r=>{if(r.message+=`
|
| 57 |
+
Please report this to https://github.com/markedjs/marked.`,t){const n="<p>An error occurred:</p><pre>"+O(r.message+"",!0)+"</pre>";return e?Promise.resolve(n):n}if(e)return Promise.reject(r);throw r}}},F=new gt;function R(t,e){return F.parse(t,e)}R.options=R.setOptions=function(t){return F.setOptions(t),R.defaults=F.defaults,st(R.defaults),R};R.getDefaults=Ie;R.defaults=Q;R.use=function(...t){return F.use(...t),R.defaults=F.defaults,st(R.defaults),R};R.walkTokens=function(t,e){return F.walkTokens(t,e)};R.parseInline=F.parseInline;R.Parser=G;R.parser=G.parse;R.Renderer=fe;R.TextRenderer=Be;R.Lexer=H;R.lexer=H.lex;R.Tokenizer=de;R.Hooks=pe;R.parse=R;R.options;R.setOptions;R.use;R.walkTokens;R.parseInline;G.parse;H.lex;const vn={"&":"&","<":"<",">":">",""":'"',"'":"'"},mt=/&(?:amp|lt|gt|quot|#(?:0+)?39);/g,yn=RegExp(mt.source),Xe=(t="")=>yn.test(t)?t.replace(mt,e=>vn[e]||"'"):t,Je=(t,e)=>{if(!e)return t;try{return new URL(t,e).href}catch{return t}};class En{constructor(e){y(this,"renderer");this.renderer=e.renderer}parse(e){this.renderer.elIdList.push(0);const r=e.map(n=>{switch(n.type){case"space":return null;case"heading":{const s=n.depth;return this.renderer.heading(this.parseInline(n.tokens),s)}case"paragraph":return this.renderer.paragraph(this.parseInline(n.tokens));case"text":{const s=n;return s.tokens?this.parseInline(s.tokens):n.text}case"blockquote":{const s=n,i=this.parse(s.tokens);return this.renderer.blockquote(i)}case"list":{const s=n;this.renderer.elIdList.push(0);const i=s.items.map(l=>{const a=[];return l.task&&a.push(this.renderer.checkbox(l.checked??!1)),a.push(this.parse(l.tokens)),this.renderer.listItem(a)});return this.renderer.elIdList.pop(),this.renderer.list(i,n.ordered,n.ordered?n.start:void 0)}case"code":return this.renderer.code(n.text,n.lang);case"html":return this.renderer.html(n.text);case"table":{const s=n;this.renderer.elIdList.push(0);const i=s.header.map((u,d)=>this.renderer.tableCell(this.parseInline(u.tokens),{header:!0,align:n.align[d]}));this.renderer.elIdList.pop();const l=this.renderer.tableRow(i),a=this.renderer.tableHeader(l);this.renderer.elIdList.push(0);const c=s.rows.map(u=>{this.renderer.elIdList.push(0);const d=u.map((h,g)=>this.renderer.tableCell(this.parseInline(h.tokens),{header:!1,align:n.align[g]}));return this.renderer.elIdList.pop(),this.renderer.tableRow(d)});this.renderer.elIdList.pop();const o=this.renderer.tableBody(c);return this.renderer.table([a,o])}case"hr":return this.renderer.hr();case"blockKatex":return this.renderer.blockKatex(n.text);case"thinkBlock":{const s=n,i=this.parse(s.tokens);return this.renderer.thinkBlock(i,s.isThinking)}default:return console.warn(`Token with "${n.type}" type was not found`),null}});return this.renderer.elIdList.pop(),r}parseInline(e=[]){this.renderer.elIdList.push(0);const r=e.map(n=>{switch(n.type){case"text":return this.renderer.text(Xe(n.text));case"strong":return this.renderer.strong(this.parseInline(n.tokens));case"em":return this.renderer.em(this.parseInline(n.tokens));case"del":return this.renderer.del(this.parseInline(n.tokens));case"codespan":return this.renderer.codespan(Xe(n.text));case"link":return this.renderer.link(n.href,this.parseInline(n.tokens));case"image":return this.renderer.image(n.href,n.text,n.title);case"html":return this.renderer.html(n.text);case"br":return this.renderer.br();case"escape":return this.renderer.text(n.text);case"inlineKatex":return this.renderer.inlineKatex(n.text);default:return console.warn(`Token with "${n.type}" type was not found`),null}});return this.renderer.elIdList.pop(),r}}var $,N,Re;class Sn{constructor(e={}){Ge(this,$);y(this,"elIdList",[]);y(this,"options");y(this,"keyPrefix","md");const{renderer:r,keyPrefix:n}=e;this.options=e,this.keyPrefix=n||"md",r&&typeof r=="object"&&Object.entries(r).forEach(([s,i])=>{const l=s,a=i;!this[l]||l==="elementId"||l==="elIdList"||l==="keyPrefix"||l==="options"||typeof a!="function"||(this[l],this[l]=(...c)=>(j(this,$,Re).call(this),a.apply(this,c)))})}get elementId(){return`${this.keyPrefix}-${this.elIdList.join("-")}`}heading(e,r){return j(this,$,N).call(this,`h${r}`,e)}paragraph(e){return j(this,$,N).call(this,"p",e)}link(e,r){const n=Je(e,this.options.baseURL),s=this.options.openLinksInNewTab?"_blank":null;return j(this,$,N).call(this,"a",r,{href:n,target:s})}image(e,r,n=null){const s=Je(e,this.options.baseURL);return j(this,$,N).call(this,"img",null,{src:s,alt:r,title:n})}codespan(e,r=null){const n=r?`${this.options.langPrefix}${r}`:null;return j(this,$,N).call(this,"code",e,{className:n})}code(e,r){return j(this,$,N).call(this,"pre",this.codespan(e,r))}blockquote(e){return j(this,$,N).call(this,"blockquote",e)}list(e,r,n){return j(this,$,N).call(this,r?"ol":"ul",e,r&&n!==1?{start:n}:{})}listItem(e){return j(this,$,N).call(this,"li",e)}checkbox(e){return j(this,$,N).call(this,"input",null,{type:"checkbox",disabled:!0,checked:e})}table(e){return j(this,$,N).call(this,"table",e)}tableHeader(e){return j(this,$,N).call(this,"thead",e)}tableBody(e){return j(this,$,N).call(this,"tbody",e)}tableRow(e){return j(this,$,N).call(this,"tr",e)}tableCell(e,r){const n=r.header?"th":"td";return j(this,$,N).call(this,n,e,{align:r.align})}strong(e){return j(this,$,N).call(this,"strong",e)}em(e){return j(this,$,N).call(this,"em",e)}del(e){return j(this,$,N).call(this,"del",e)}text(e){return e}html(e){return e}hr(){return j(this,$,N).call(this,"hr")}br(){return j(this,$,N).call(this,"br")}inlineKatex(e){return e}blockKatex(e){return e}thinkBlock(e,r){return e}}$=new WeakSet,N=function(e,r=null,n={}){const s={key:`${this.keyPrefix}-${this.elementId}`};return j(this,$,Re).call(this),f.createElement(e,{...n,...s},r)},Re=function(){this.elIdList[this.elIdList.length-1]+=1};function Rn(t={}){return{extensions:[$n(),_n(),Tn()]}}function $n(t){return{name:"inlineKatex",level:"inline",start(e){const r=e.indexOf("$"),n=e.indexOf("\\[");return Math.min(r===-1?1/0:r,n===-1?1/0:n)},tokenizer(e,r){const n=e.match(new RegExp("^\\$+((?:[^$]|(?<!\\\\)\\$)*?)(?:\\$+|$)"));if(n)return{type:"inlineKatex",raw:n[0],text:n[1].trim()};const s=e.match(/\\\[((?:[^\\]|\\[^\]])*?)(?:\\\]|$)/);if(s)return{type:"inlineKatex",raw:s[0],text:s[1].trim()}}}}function _n(t){return{name:"blockKatex",level:"block",start(e){return e.indexOf("$$")},tokenizer(e,r){const n=e.match(/^\$\$+\n([^$]+?)\n\$\$/);if(n)return{type:"blockKatex",raw:n[0],text:n[1].trim()}}}}function Tn(){return{name:"thinkBlock",level:"block",start(t){return t.indexOf("<think>")},tokenizer(t,e){const r=t.match(/<think>([\s\S]*?)(<\/think>|$)/);if(r){const n={type:"thinkBlock",raw:r[0],text:r[1].trim(),tokens:[],isThinking:r[2]===""};return this.lexer.blockTokens(n.text,n.tokens),n}}}}const In=t=>{if(t.value&&typeof t.value!="string")throw new TypeError(`[marked-react]: Expected value to be of type string but got ${typeof t.value}`);if(t.children&&typeof t.children!="string")throw new TypeError(`[marked-react]: Expected children to be of type string but got ${typeof t.children}`)},jn={isInline:!1,breaks:!1,gfm:!0,baseURL:void 0,openLinksInNewTab:!0,langPrefix:"language-",renderer:void 0},xt=new gt;xt.use(Rn({}));const Nn=t=>{In(t);const e={...jn,...t},r=e.instance??xt,n={breaks:e.breaks,gfm:e.gfm,extensions:r.defaults.extensions},s=e.value??e.children??"",i=e.isInline?r.Lexer.lexInline(s,n):r.lexer(s,n),l={renderer:new Sn({renderer:e.renderer,baseURL:e.baseURL,openLinksInNewTab:e.openLinksInNewTab,langPrefix:e.langPrefix})},a=new En(l),c=e.isInline?a.parseInline(i):a.parse(i);return f.createElement(f.Fragment,null,c)},Cn="_PromptEditor_11a96_1",Ln="_PromptEditorInner_11a96_9",Pn="_promptAction_11a96_68",An="_promptActionLeft_11a96_76",zn="_promptActionRight_11a96_77",Bn="_promptEmotion_11a96_96",Mn="_promptEmotionLeft_11a96_104",Dn="_promptEmotionRight_11a96_105",On="_invisibleScrollbar_11a96_135",Z={PromptEditor:Cn,PromptEditorInner:Ln,promptAction:Pn,promptActionLeft:An,promptActionRight:zn,promptEmotion:Bn,promptEmotionLeft:Mn,promptEmotionRight:Dn,invisibleScrollbar:On},qn={cover:!0},Zn=[{re:/\*\[(.*?)\]\*/g,replace:`<span class="${Z.promptAction}"><span class=${Z.promptActionLeft}>*[</span>$1<span class=${Z.promptActionRight}>]*</span></span>`},{re:/\*\((.*?)\)\*/g,replace:`<span class="${Z.promptEmotion}"><span class=${Z.promptEmotionLeft}>*[</span>$1<span class=${Z.promptEmotionRight}>]*</span></span>`}],Hn=({value:t,onChange:e=()=>{},style:r={},editable:n=!1,placeholder:s=void 0,disabled:i=!1,innerRef:l,invisibleScrollbar:a=!1,isFocus:c=!1,setIsFocus:o=h=>{},isKeepFocus:u,className:d})=>{const[h,g]=f.useState(t),[x,S]=f.useState(qn),T=f.useRef(null),m=b=>([{re:/</g,replace:"<"},{re:/>/g,replace:">"},{re:/\n/g,replace:"<br>"},{re:/<br>$/,replace:"<br><br>"},...x.cover?Zn:[]].forEach(B=>{b=b.replace(B.re,B.replace)}),b===""?"<br>":b),w=(b,B,D,ke)=>{if(T.current.selectionStart||T.current.selectionStart==0){const ee=Math.min(T.current.selectionStart,T.current.selectionEnd),be=Math.max(T.current.selectionStart,T.current.selectionEnd);g(X=>{const U=`${X.substring(0,ee)}${b}${D}${B}${X.substring(be,X.length)}`;return setTimeout(()=>{e(U)},0),U}),setTimeout(()=>{T.current.selectionEnd=ee+D.length,T.current.focus()},0)}},I=(b,B)=>w("","",b),k=b=>{(b.ctrlKey||b.altKey)&&b.key==="Enter"&&(b.stopPropagation(),I(`
|
| 58 |
+
`))};f.useEffect(()=>{g(t)},[t]),f.useEffect(()=>{var b;c&&((b=T.current)==null||b.focus())},[c]);const v=()=>{o(!0)},L=()=>{var b;u!=null&&u.current?(b=T.current)==null||b.focus():o(!1)};return p.jsx("div",{style:r,className:`${Z.PromptEditor} ${a?Z.invisibleScrollbar:""} ${d||""}`,children:p.jsxs("div",{className:Z.PromptEditorInner,style:{opacity:i?"0.5":void 0},children:[n===!0&&p.jsx("textarea",{value:h,onChange:b=>{g(b.target.value),e(b.target.value)},placeholder:s,disabled:i,ref:T,onFocus:v,onBlur:L,onKeyDown:k}),p.jsx("div",{dangerouslySetInnerHTML:{__html:m(h)},ref:l})]})})},Gn=""+new URL("new-sug-Cn4p8TNH.json",import.meta.url).href,Kn=Tt()(It(t=>({cachedSuggestions:null,lastFetchTime:null,setCachedSuggestions:e=>t({cachedSuggestions:e,lastFetchTime:Date.now()}),clearCache:()=>t({cachedSuggestions:null,lastFetchTime:null})}),{name:"suggestion-storage"}));async function Ye(){const t=await fetch(Gn);if(!t.ok)throw new Error("Failed to fetch suggestions");return await t.json()}function $e(){return $e=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},$e.apply(null,arguments)}function kt(t,e){if(t==null)return{};var r={};for(var n in t)if({}.hasOwnProperty.call(t,n)){if(e.includes(n))continue;r[n]=t[n]}return r}function _e(t,e){return _e=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(r,n){return r.__proto__=n,r},_e(t,e)}function Me(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,_e(t,e)}function Un(t,e){return t.classList?!!e&&t.classList.contains(e):(" "+(t.className.baseVal||t.className)+" ").indexOf(" "+e+" ")!==-1}function Vn(t,e){t.classList?t.classList.add(e):Un(t,e)||(typeof t.className=="string"?t.className=t.className+" "+e:t.setAttribute("class",(t.className&&t.className.baseVal||"")+" "+e))}function et(t,e){return t.replace(new RegExp("(^|\\s)"+e+"(?:\\s|$)","g"),"$1").replace(/\s+/g," ").replace(/^\s*|\s*$/g,"")}function Wn(t,e){t.classList?t.classList.remove(e):typeof t.className=="string"?t.className=et(t.className,e):t.setAttribute("class",et(t.className&&t.className.baseVal||"",e))}const tt={disabled:!1},De=C.createContext(null);var bt=function(e){return e.scrollTop},re="unmounted",W="exited",M="entering",q="entered",ie="exiting",K=(function(t){Me(e,t);function e(n,s){var i;i=t.call(this,n,s)||this;var l=s,a=l&&!l.isMounting?n.enter:n.appear,c;return i.appearStatus=null,n.in?a?(c=W,i.appearStatus=M):c=q:n.unmountOnExit||n.mountOnEnter?c=re:c=W,i.state={status:c},i.nextCallback=null,i}e.getDerivedStateFromProps=function(s,i){var l=s.in;return l&&i.status===re?{status:W}:null};var r=e.prototype;return r.componentDidMount=function(){this.updateStatus(!0,this.appearStatus)},r.componentDidUpdate=function(s){var i=null;if(s!==this.props){var l=this.state.status;this.props.in?l!==M&&l!==q&&(i=M):(l===M||l===q)&&(i=ie)}this.updateStatus(!1,i)},r.componentWillUnmount=function(){this.cancelNextCallback()},r.getTimeouts=function(){var s=this.props.timeout,i,l,a;return i=l=a=s,s!=null&&typeof s!="number"&&(i=s.exit,l=s.enter,a=s.appear!==void 0?s.appear:l),{exit:i,enter:l,appear:a}},r.updateStatus=function(s,i){if(s===void 0&&(s=!1),i!==null)if(this.cancelNextCallback(),i===M){if(this.props.unmountOnExit||this.props.mountOnEnter){var l=this.props.nodeRef?this.props.nodeRef.current:le.findDOMNode(this);l&&bt(l)}this.performEnter(s)}else this.performExit();else this.props.unmountOnExit&&this.state.status===W&&this.setState({status:re})},r.performEnter=function(s){var i=this,l=this.props.enter,a=this.context?this.context.isMounting:s,c=this.props.nodeRef?[a]:[le.findDOMNode(this),a],o=c[0],u=c[1],d=this.getTimeouts(),h=a?d.appear:d.enter;if(!s&&!l||tt.disabled){this.safeSetState({status:q},function(){i.props.onEntered(o)});return}this.props.onEnter(o,u),this.safeSetState({status:M},function(){i.props.onEntering(o,u),i.onTransitionEnd(h,function(){i.safeSetState({status:q},function(){i.props.onEntered(o,u)})})})},r.performExit=function(){var s=this,i=this.props.exit,l=this.getTimeouts(),a=this.props.nodeRef?void 0:le.findDOMNode(this);if(!i||tt.disabled){this.safeSetState({status:W},function(){s.props.onExited(a)});return}this.props.onExit(a),this.safeSetState({status:ie},function(){s.props.onExiting(a),s.onTransitionEnd(l.exit,function(){s.safeSetState({status:W},function(){s.props.onExited(a)})})})},r.cancelNextCallback=function(){this.nextCallback!==null&&(this.nextCallback.cancel(),this.nextCallback=null)},r.safeSetState=function(s,i){i=this.setNextCallback(i),this.setState(s,i)},r.setNextCallback=function(s){var i=this,l=!0;return this.nextCallback=function(a){l&&(l=!1,i.nextCallback=null,s(a))},this.nextCallback.cancel=function(){l=!1},this.nextCallback},r.onTransitionEnd=function(s,i){this.setNextCallback(i);var l=this.props.nodeRef?this.props.nodeRef.current:le.findDOMNode(this),a=s==null&&!this.props.addEndListener;if(!l||a){setTimeout(this.nextCallback,0);return}if(this.props.addEndListener){var c=this.props.nodeRef?[this.nextCallback]:[l,this.nextCallback],o=c[0],u=c[1];this.props.addEndListener(o,u)}s!=null&&setTimeout(this.nextCallback,s)},r.render=function(){var s=this.state.status;if(s===re)return null;var i=this.props,l=i.children;i.in,i.mountOnEnter,i.unmountOnExit,i.appear,i.enter,i.exit,i.timeout,i.addEndListener,i.onEnter,i.onEntering,i.onEntered,i.onExit,i.onExiting,i.onExited,i.nodeRef;var a=kt(i,["children","in","mountOnEnter","unmountOnExit","appear","enter","exit","timeout","addEndListener","onEnter","onEntering","onEntered","onExit","onExiting","onExited","nodeRef"]);return C.createElement(De.Provider,{value:null},typeof l=="function"?l(s,a):C.cloneElement(C.Children.only(l),a))},e})(C.Component);K.contextType=De;K.propTypes={};function J(){}K.defaultProps={in:!1,mountOnEnter:!1,unmountOnExit:!1,appear:!1,enter:!0,exit:!0,onEnter:J,onEntering:J,onEntered:J,onExit:J,onExiting:J,onExited:J};K.UNMOUNTED=re;K.EXITED=W;K.ENTERING=M;K.ENTERED=q;K.EXITING=ie;var Fn=function(e,r){return e&&r&&r.split(" ").forEach(function(n){return Vn(e,n)})},we=function(e,r){return e&&r&&r.split(" ").forEach(function(n){return Wn(e,n)})},Oe=(function(t){Me(e,t);function e(){for(var n,s=arguments.length,i=new Array(s),l=0;l<s;l++)i[l]=arguments[l];return n=t.call.apply(t,[this].concat(i))||this,n.appliedClasses={appear:{},enter:{},exit:{}},n.onEnter=function(a,c){var o=n.resolveArguments(a,c),u=o[0],d=o[1];n.removeClasses(u,"exit"),n.addClass(u,d?"appear":"enter","base"),n.props.onEnter&&n.props.onEnter(a,c)},n.onEntering=function(a,c){var o=n.resolveArguments(a,c),u=o[0],d=o[1],h=d?"appear":"enter";n.addClass(u,h,"active"),n.props.onEntering&&n.props.onEntering(a,c)},n.onEntered=function(a,c){var o=n.resolveArguments(a,c),u=o[0],d=o[1],h=d?"appear":"enter";n.removeClasses(u,h),n.addClass(u,h,"done"),n.props.onEntered&&n.props.onEntered(a,c)},n.onExit=function(a){var c=n.resolveArguments(a),o=c[0];n.removeClasses(o,"appear"),n.removeClasses(o,"enter"),n.addClass(o,"exit","base"),n.props.onExit&&n.props.onExit(a)},n.onExiting=function(a){var c=n.resolveArguments(a),o=c[0];n.addClass(o,"exit","active"),n.props.onExiting&&n.props.onExiting(a)},n.onExited=function(a){var c=n.resolveArguments(a),o=c[0];n.removeClasses(o,"exit"),n.addClass(o,"exit","done"),n.props.onExited&&n.props.onExited(a)},n.resolveArguments=function(a,c){return n.props.nodeRef?[n.props.nodeRef.current,a]:[a,c]},n.getClassNames=function(a){var c=n.props.classNames,o=typeof c=="string",u=o&&c?c+"-":"",d=o?""+u+a:c[a],h=o?d+"-active":c[a+"Active"],g=o?d+"-done":c[a+"Done"];return{baseClassName:d,activeClassName:h,doneClassName:g}},n}var r=e.prototype;return r.addClass=function(s,i,l){var a=this.getClassNames(i)[l+"ClassName"],c=this.getClassNames("enter"),o=c.doneClassName;i==="appear"&&l==="done"&&o&&(a+=" "+o),l==="active"&&s&&bt(s),a&&(this.appliedClasses[i][l]=a,Fn(s,a))},r.removeClasses=function(s,i){var l=this.appliedClasses[i],a=l.base,c=l.active,o=l.done;this.appliedClasses[i]={},a&&we(s,a),c&&we(s,c),o&&we(s,o)},r.render=function(){var s=this.props;s.classNames;var i=kt(s,["classNames"]);return C.createElement(K,$e({},i,{onEnter:this.onEnter,onEntered:this.onEntered,onEntering:this.onEntering,onExit:this.onExit,onExiting:this.onExiting,onExited:this.onExited}))},e})(C.Component);Oe.defaultProps={classNames:""};Oe.propTypes={};var ce,ue;function Qn(t,e){return!(t===e||C.isValidElement(t)&&C.isValidElement(e)&&t.key!=null&&t.key===e.key)}var Y={out:"out-in",in:"in-out"},ge=function(e,r,n){return function(){var s;e.props[r]&&(s=e.props)[r].apply(s,arguments),n()}},Xn=(ce={},ce[Y.out]=function(t){var e=t.current,r=t.changeState;return C.cloneElement(e,{in:!1,onExited:ge(e,"onExited",function(){r(M,null)})})},ce[Y.in]=function(t){var e=t.current,r=t.changeState,n=t.children;return[e,C.cloneElement(n,{in:!0,onEntered:ge(n,"onEntered",function(){r(M)})})]},ce),Jn=(ue={},ue[Y.out]=function(t){var e=t.children,r=t.changeState;return C.cloneElement(e,{in:!0,onEntered:ge(e,"onEntered",function(){r(q,C.cloneElement(e,{in:!0}))})})},ue[Y.in]=function(t){var e=t.current,r=t.children,n=t.changeState;return[C.cloneElement(e,{in:!1,onExited:ge(e,"onExited",function(){n(q,C.cloneElement(r,{in:!0}))})}),C.cloneElement(r,{in:!0})]},ue),qe=(function(t){Me(e,t);function e(){for(var n,s=arguments.length,i=new Array(s),l=0;l<s;l++)i[l]=arguments[l];return n=t.call.apply(t,[this].concat(i))||this,n.state={status:q,current:null},n.appeared=!1,n.changeState=function(a,c){c===void 0&&(c=n.state.current),n.setState({status:a,current:c})},n}var r=e.prototype;return r.componentDidMount=function(){this.appeared=!0},e.getDerivedStateFromProps=function(s,i){return s.children==null?{current:null}:i.status===M&&s.mode===Y.in?{status:M}:i.current&&Qn(i.current,s.children)?{status:ie}:{current:C.cloneElement(s.children,{in:!0})}},r.render=function(){var s=this.props,i=s.children,l=s.mode,a=this.state,c=a.status,o=a.current,u={children:i,current:o,changeState:this.changeState,status:c},d;switch(c){case M:d=Jn[l](u);break;case ie:d=Xn[l](u);break;case q:d=o}return C.createElement(De.Provider,{value:{isMounting:!this.appeared}},d)},e})(C.Component);qe.propTypes={};qe.defaultProps={mode:Y.out};function Te({enableReasoning:t,...e}){return p.jsxs("svg",{...e,viewBox:"0 0 1024 1024",xmlns:"http://www.w3.org/2000/svg",className:_("size-5",e.className),strokeWidth:1.5,children:[p.jsx("path",{d:"M874.496 385.109333c-93.141333-39.68-218.282667-65.28-352-72.32-21.333333-1.28-42.112-1.706667-61.866667-1.706666 98.901333-120.746667 204.885333-201.813333 274.645334-204.373334 13.738667-0.554667 25.386667 2.346667 34.688 8.362667 30.122667 19.541333 38.613333 75.434667 23.253333 153.173333-1.706667 10.666667 5.12 21.034667 15.36 23.04 10.666667 2.133333 20.906667-4.693333 23.04-15.36 19.2-97.28 5.12-164.096-40.106667-193.621333-16.213333-10.581333-35.84-15.573333-57.6-14.762667-87.466667 3.285333-210.773333 98.133333-323.84 244.053334-49.237333 1.493333-95.573333 5.546667-137.898666 12.245333-27.562667-123.605333-16.64-212.352 25.344-233.685333 5.888-3.114667 12.16-4.693333 19.498666-5.290667 29.738667-2.304 70.826667 16.853333 115.626667 54.186667 8.277333 6.826667 20.736 5.973333 27.562667-2.56a19.541333 19.541333 0 0 0-2.56-27.52C403.882667 64.426667 354.304 42.666667 313.770667 45.653333a95.744 95.744 0 0 0-34.261334 9.386667c-50.773333 25.898667-71.253333 99.285333-58.453333 206.421333 2.986667 22.186667 6.826667 45.312 12.373333 69.12C93.44 358.570667 4.266667 414.634667 0.426667 485.205333c-2.56 49.92 36.906667 97.450667 114.346666 137.472a19.626667 19.626667 0 1 0 17.92-34.816C70.826667 556.032 37.546667 520.106667 39.552 487.253333c2.133333-46.08 75.605333-93.44 203.093333-118.613333 11.52 42.410667 26.453333 86.698667 44.8 131.84-43.434667 80.554667-74.922667 159.872-91.178666 230.4-23.893333 105.173333-11.093333 180.053333 36.693333 211.114667 15.36 9.984 33.28 14.933333 53.205333 14.933333 39.893333 0 88.192-19.626667 142.805334-58.538667a19.541333 19.541333 0 1 0-22.613334-31.829333c-65.877333 47.061333-121.344 62.805333-151.978666 42.794667-32.426667-21.12-39.509333-82.901333-19.626667-169.642667 13.653333-59.136 38.698667-125.013333 72.874667-192.853333 8.533333 18.688 17.493333 37.376 26.88 56.021333 60.8 119.296 135.253333 223.018667 209.493333 292.053333 59.136 55.04 114.090667 83.754667 159.36 83.754667 14.933333 0 29.013333-3.2 41.642667-9.514667 48.853333-24.96 69.973333-94.293333 59.648-195.2-9.557333-94.421333-45.226667-209.493333-100.437334-324.266666a19.626667 19.626667 0 1 0-35.413333 16.896c114.773333 239.018667 122.88 434.773333 58.453333 467.626666-67.84 34.688-231.424-100.48-357.973333-349.013333-14.506667-27.946667-27.178667-55.466667-38.4-82.346667 14.506667-25.941333 29.866667-52.053333 46.72-78.08 16.853333-25.770667 34.389333-50.688 52.224-74.453333h16.810667c23.04 0 48.042667 0.426667 73.984 2.048 278.613333 14.634667 468.266667 109.226667 464.384 184.917333-1.706667 32.64-39.424 65.621333-103.466667 90.453334a19.797333 19.797333 0 0 0-11.093333 25.429333 19.413333 19.413333 0 0 0 25.301333 11.178667c81.28-31.573333 125.866667-74.922667 128.426667-125.013334 2.986667-56.746667-49.92-111.36-149.333334-153.6v-0.426666zM344.746667 403.2c-11.52 17.706667-22.186667 35.285333-32.597334 53.077333a1009.493333 1009.493333 0 0 1-30.848-94.506666c30.421333-4.693333 63.36-8.106667 98.56-10.24-11.946667 16.64-23.637333 33.877333-34.986666 51.626666v-0.426666z",fill:"currentColor",className:_("transition-all duration-500",t?"text-yellow-500":"text-gray-500 dark:text-zinc-300")}),p.jsx("path",{d:"M512.213333 512m-58.666666 0a58.666667 58.666667 0 1 0 117.333333 0 58.666667 58.666667 0 1 0-117.333333 0Z",fill:"currentColor",className:"text-yellow-400"})]})}function Yn({promptContent:t,children:e,onClick:r,className:n,style:s,isKeepFocus:i,...l}){return p.jsxs("button",{className:_("flex rounded-2xl p-2 text-left text-sm md:hover:bg-gray-100 md:dark:hover:bg-zinc-600/50",n),onClick:a=>{r(t)},onTouchStart:()=>{i&&(i.current=!0,setTimeout(()=>{i.current=!1},500))},onMouseDown:()=>{i&&(i.current=!0,setTimeout(()=>{i.current=!1},500))},style:s,...l,children:[p.jsx("div",{className:"p-0.5",children:p.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"size-4",children:p.jsx("path",{d:"M6.28 5.22a.75.75 0 0 0-1.06 1.06l7.22 7.22H6.75a.75.75 0 0 0 0 1.5h7.5a.747.747 0 0 0 .75-.75v-7.5a.75.75 0 0 0-1.5 0v5.69L6.28 5.22Z"})})}),p.jsx("div",{className:"flex-1",children:e})]})}function er({setValue:t,isPannelExpaned:e,isKeepFocus:r}){var T;const[n,s]=f.useState([]),{cachedSuggestions:i,setCachedSuggestions:l}=Kn(),[a,c]=f.useState(null),o=f.useRef(!0),u=f.useRef(null),d=f.useRef(null),{i18n:h}=At();f.useEffect(()=>{(async()=>{var w;c(null);try{let I=i;I||(I=await Ye(),l(I),o.current=!1);const k=Bt()||"zh",v=((w=I[k])==null?void 0:w.chat)||[];s(v),o.current&&(I=await Ye(),l(I),o.current=!1)}catch(I){console.error("Failed to load suggestions:",I)}})()},[h.locale]),f.useEffect(()=>{e||c(null)},[e]);const{contextSafe:g}=zt({scope:d}),x=g(m=>{let w=Ke.timeline();w.to(m,{y:1,duration:.07}),w.to(m,{y:-8,duration:.3,ease:"power4.out"}),w.to(m,{y:2,duration:.09}),w.to(m,{y:0,duration:.08})}),S=g(m=>{let w=Ke.timeline();w.to(m,{y:2,duration:.1}),w.to(m,{y:0,duration:.17})});return p.jsxs(p.Fragment,{children:[p.jsx("div",{className:_("max-h-[20vh] overflow-hidden transition-all duration-300 [mask-image:linear-gradient(00deg,#0000_0,#ffff_1rem,#ffff_calc(100%-1rem),#0000_100%)] md:max-h-none",a?"h-60":"h-0"),children:p.jsx(qe,{children:p.jsx(Oe,{nodeRef:u,addEndListener:m=>{var w;(w=u.current)==null||w.addEventListener("transitionend",m,!1)},classNames:{enter:"opacity-0",enterActive:"!opacity-100 transition-opacity duration-75",exit:"opacity-100",exitActive:"!opacity-0 transition-opacity duration-300 test"},children:p.jsx("div",{ref:u,className:_("invisibleScrollbar hideScrollbar flex h-full flex-col gap-2 overflow-auto p-2",a?"":"!duration-75"),children:a?(T=n.find(m=>m.name===a))==null?void 0:T.items.map((m,w)=>p.jsx(Yn,{promptContent:m.prompt,onClick:()=>{t(m.prompt&&m.prompt!==""?m.prompt:m.display||m.prompt)},className:_("motion-duration-300",w<8?"motion-translate-y-in-[30px] motion-opacity-in-0":"intersect:motion-translate-y-in-[30px] intersect:motion-opacity-in-0"),style:{...w<8?{"--motion-delay":`${w*100}ms`}:{}},isKeepFocus:r,children:m.display||m.prompt},`${m.prompt}-${w}`)):null},a||"none")},a||"none")})}),p.jsx("div",{ref:d,className:_("invisibleScrollbar hideScrollbar relative flex flex-nowrap items-center gap-3 overflow-auto overflow-y-hidden text-nowrap px-3 transition-all duration-500 md:px-5",e?"h-12 md:h-16":"h-0"),children:n.map((m,w)=>p.jsx("button",{className:_("h-7 flex-shrink-0 select-none rounded-3xl px-2 py-1.5 text-xs outline outline-1 outline-slate-400 transition-[opacity,background-color] duration-300 md:hover:bg-gray-100 md:dark:hover:bg-zinc-600/50",e?"opacity-100":"opacity-0",a===m.name&&"shadow-md",`sg-select-${m.name.replaceAll(/[^\w\u4e00-\u9fff]/g,"-")}`),style:{transitionDelay:e?`${Math.min(400+w*50,2e3)}ms,0ms`:void 0},onClick:I=>{a!==m.name?(c(m.name),x(`.sg-select-${m.name.replaceAll(/[^\w\u4e00-\u9fff]/g,"-")}`)):(S(`.sg-select-${m.name.replaceAll(/[^\w\u4e00-\u9fff]/g,"-")}`),c(null))},onTouchStart:()=>{r&&(r.current=!0,setTimeout(()=>{r.current=!1},500))},onMouseDown:()=>{r&&(r.current=!0,setTimeout(()=>{r.current=!1},500))},children:m.name},m.name))})]})}function dr({className:t,maxLines:e=8,onSubmit:r=()=>{},submitShortcutOnMobile:n=!1,currentModelName:s,...i}){const[l,a]=f.useState(""),c=f.useRef(null),[o,u]=f.useState(1),[d,h]=f.useState(!1),[g,x]=f.useState(!1),{llmModel:S,loadingModelTitle:T}=jt(P=>P),{selectedModelTitle:m,supportReasoning:w,currentInferPort:I}=Nt(S),[k,v]=f.useState(S.isEnableReasoning),[L,b]=f.useState(Ct._({id:"s1jQ2s"}));f.useRef(null);const B=f.useRef(null),D=f.useRef(!1),ke=24;f.useEffect(()=>{setTimeout(()=>{c.current&&u(c.current.scrollHeight/ke)},0)},[l]);const ee=P=>{P.trim()!==""&&(r(P.trim(),k),a(""),Ze(0),x(!1),h(!1))},be=P=>{P.key==="Enter"&&!P.shiftKey&&window.matchMedia("(min-width: 768px)").matches&&(P.stopPropagation(),P.preventDefault(),ee(l))},X=()=>{B.current.setIsModalOpen(!0)},U=f.useRef(),Ze=P=>{clearTimeout(U.current),U.current=setTimeout(()=>{x(!1),U.current=void 0},P)};return f.useEffect(()=>{clearTimeout(U.current),d?(window.dispatchEvent(new Event("rwkv:input-focus")),x(!0),U.current=void 0):l===""&&Ze(300)},[d,l]),f.useEffect(()=>{S.isEnableReasoning=k},[k]),f.useEffect(()=>{S.supportReasoning?(S.isEnableReasoning=S.isEnableReasoning?!0:k,v(S.isEnableReasoning)):v(!1)},[S]),p.jsxs("div",{className:_("relative flex flex-col overflow-hidden rounded-[1.75rem] outline outline-1 outline-slate-400 transition-[height] ease-out",t),children:[p.jsx(Lt,{ref:B,children:({close:P})=>p.jsx(Pt,{close:P})}),p.jsx(er,{setValue:a,isKeepFocus:D,isPannelExpaned:g}),p.jsxs("div",{className:_("flex flex-shrink-0 rounded-[1.75rem] transition-[height] ease-out"),style:{height:`${(o>1?32:56)+(Math.min(Math.max(1,o),e)-1)*ke}px`},onKeyDown:P=>be(P),children:[p.jsx("div",{className:_("flex justify-end gap-1 transition-all duration-500",g?"pointer-events-none w-0 opacity-0":"w-[52px]",!w&&"pointer-events-none w-0 opacity-0"),children:p.jsx("button",{className:_("my-2 mr-1 h-10 w-10 self-end rounded-full p-2.5 text-slate-500 transition-[color,background-color] duration-500 dark:text-zinc-200",k?"md:hover:bg-yellow-500/10 dark:md:hover:bg-yellow-500/20":"md:hover:bg-slate-100 dark:md:hover:bg-slate-200/20"),onClick:()=>v(!k),title:k?"推理开:思考模式":"推理关:快思考模式",children:p.jsx(Te,{enableReasoning:k})})}),p.jsx("div",{className:_("flex-1 cursor-text overflow-auto py-4 transition-all duration-500",!w&&"pl-5",g&&"pl-3 md:pl-5",o>1&&"py-0"),onClick:()=>{h(!0)},children:p.jsx(Hn,{value:l,onChange:P=>{a(P)},placeholder:L,editable:!0,innerRef:c,invisibleScrollbar:o<=e,isFocus:d,setIsFocus:h,isKeepFocus:D,className:"caret-black dark:caret-zinc-300"})}),p.jsx("button",{className:_("absolute bottom-0 right-0 m-2 h-10 w-10 self-end rounded-full p-2.5 text-slate-400 transition-[background-color,margin] duration-[200ms,500ms] dark:text-zinc-400 md:hover:bg-slate-100",l.trim()!==""&&"text-slate-600 dark:text-zinc-300",g?"max-md:my-0":""),onClick:()=>{ee(l)},children:p.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"size-5",children:p.jsx("path",{d:"M3.105 2.288a.75.75 0 0 0-.826.95l1.414 4.926A1.5 1.5 0 0 0 5.135 9.25h6.115a.75.75 0 0 1 0 1.5H5.135a1.5 1.5 0 0 0-1.442 1.086l-1.414 4.926a.75.75 0 0 0 .826.95 28.897 28.897 0 0 0 15.293-7.155.75.75 0 0 0 0-1.114A28.897 28.897 0 0 0 3.105 2.288Z"})})})]}),p.jsxs("div",{className:_("center invisibleScrollbar mr-11 flex gap-1 overflow-hidden overflow-x-auto pl-3 pr-3 transition-all duration-500 [mask-image:linear-gradient(90deg,#ffff_calc(100%_-_1rem),_#0000_100%)] md:pl-5"),children:[p.jsx("div",{className:_("flex h-10 flex-shrink-0 items-center transition-all duration-500 md:h-14",w&&g?"":"-mb-10 md:-mb-14"),children:p.jsxs("button",{className:_("flex h-6 items-center gap-2 rounded-full border px-2 text-slate-500 transition-all duration-500 dark:text-slate-300 md:hover:bg-slate-100 dark:md:hover:bg-zinc-600/70",w&&g?"":"pointer-events-none opacity-0",k?"border-yellow-600 bg-yellow-500/10 text-yellow-600 dark:text-yellow-600 md:hover:bg-yellow-500/20 dark:md:hover:bg-yellow-500/30":"border-slate-400 text-slate-500"),onTouchStart:()=>{D&&(D.current=!0,setTimeout(()=>{D.current=!1},500))},onMouseDown:()=>{D&&(D.current=!0,setTimeout(()=>{D.current=!1},500))},onClick:()=>v(!k),children:[p.jsx(Te,{enableReasoning:k}),p.jsx("span",{children:p.jsx(V,{id:"wUf2OL"})})]})}),p.jsx("div",{className:_("items-transition-all ml-auto flex h-10 flex-shrink-0 items-center text-sm text-gray-500/50 duration-500 dark:text-zinc-400 md:h-14",g?"":"-mb-10 md:-mb-14"),children:p.jsxs("span",{className:_("flex h-8 items-center text-nowrap transition-all",g?"opacity-100":"opacity-0"),children:[s?p.jsx("span",{className:"motion-preset-slide-left-sm",children:p.jsx(V,{id:"Kwc7rD",values:{currentModelName:s},components:{0:p.jsx("span",{className:"font-semibold"})}})},0):p.jsx("span",{className:"motion-preset-slide-right-sm",children:p.jsx(V,{id:"VCOI02",values:{0:I.current&&(k&&I.current.portType==="api"?I.current.reasoningModelName:I.current.selectedModelTitle)}})},1),p.jsx("button",{className:"pl-2",onClick:X,children:p.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"size-4",children:p.jsx("path",{fillRule:"evenodd",d:"M11.078 2.25c-.917 0-1.699.663-1.85 1.567L9.05 4.889c-.02.12-.115.26-.297.348a7.493 7.493 0 0 0-.986.57c-.166.115-.334.126-.45.083L6.3 5.508a1.875 1.875 0 0 0-2.282.819l-.922 1.597a1.875 1.875 0 0 0 .432 2.385l.84.692c.095.078.17.229.154.43a7.598 7.598 0 0 0 0 1.139c.015.2-.059.352-.153.43l-.841.692a1.875 1.875 0 0 0-.432 2.385l.922 1.597a1.875 1.875 0 0 0 2.282.818l1.019-.382c.115-.043.283-.031.45.082.312.214.641.405.985.57.182.088.277.228.297.35l.178 1.071c.151.904.933 1.567 1.85 1.567h1.844c.916 0 1.699-.663 1.85-1.567l.178-1.072c.02-.12.114-.26.297-.349.344-.165.673-.356.985-.57.167-.114.335-.125.45-.082l1.02.382a1.875 1.875 0 0 0 2.28-.819l.923-1.597a1.875 1.875 0 0 0-.432-2.385l-.84-.692c-.095-.078-.17-.229-.154-.43a7.614 7.614 0 0 0 0-1.139c-.016-.2.059-.352.153-.43l.84-.692c.708-.582.891-1.59.433-2.385l-.922-1.597a1.875 1.875 0 0 0-2.282-.818l-1.02.382c-.114.043-.282.031-.449-.083a7.49 7.49 0 0 0-.985-.57c-.183-.087-.277-.227-.297-.348l-.179-1.072a1.875 1.875 0 0 0-1.85-1.567h-1.843ZM12 15.75a3.75 3.75 0 1 0 0-7.5 3.75 3.75 0 0 0 0 7.5Z",clipRule:"evenodd"})})})]})})]}),p.jsxs("div",{className:_("group absolute bottom-0 left-0 right-0 top-0 flex cursor-pointer items-center backdrop-blur-sm transition-all duration-300",m===null?"":"pointer-events-none scale-95 opacity-0"),onClick:()=>{T===null&&X()},children:[p.jsx("div",{className:_("m-2 flex h-10 w-10 items-center justify-center self-end rounded-full text-slate-800 dark:text-zinc-300"),children:p.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"currentColor",className:"size-6",children:p.jsx("path",{fillRule:"evenodd",d:"M12.97 3.97a.75.75 0 0 1 1.06 0l7.5 7.5a.75.75 0 0 1 0 1.06l-7.5 7.5a.75.75 0 1 1-1.06-1.06l6.22-6.22H3a.75.75 0 0 1 0-1.5h16.19l-6.22-6.22a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"})})}),p.jsx("div",{className:"flex h-14 w-0 flex-1 cursor-pointer items-center self-end p-2",children:m===null&&(T===null?p.jsx("span",{className:"transition-all group-active:scale-95 max-md:text-xs",children:p.jsx(V,{id:"pG1YQf"})}):p.jsx(p.Fragment,{children:p.jsx(V,{id:"GFKKZL",values:{loadingModelTitle:T},components:{0:p.jsx("span",{className:"font-semibold underline transition-all group-active:scale-95"}),1:p.jsx("span",{className:"ml-2 text-xs text-slate-300 transition-all group-active:scale-95 md:static"})}})}))})]})]})}const tr=f.lazy(()=>rt(()=>import("./CodeHighlight-DL4bOcf6.js"),__vite__mapDeps([0,1,2,3]),import.meta.url)),wt=f.lazy(()=>rt(()=>import("./KatexRender-DV7TN3VL.js"),__vite__mapDeps([4,1,2,5]),import.meta.url));function nr({children:t,className:e,...r}){const[n,s]=f.useState(!!e);return n?p.jsx("span",{...r,className:e,onAnimationEnd:()=>s(!1),children:t}):t}function vt({children:t,animate:e=!1}){const[r,n]=f.useState([]),s=f.useRef(0),i=f.useRef(""),l=f.useRef([]),a=f.useRef(Math.random());return f.useEffect(()=>{if(t.startsWith(i.current)&&t.length>s.current)l.current=[...l.current,p.jsx(nr,{className:`${e&&"motion-opacity-in-0 motion-duration-1000"||""}`,children:t.slice(s.current)},`${t.length}-${a.current}`)],s.current=t.length,i.current=t;else if(i.current.startsWith(t)&&t.length<s.current){const c=l.current.filter(o=>parseInt(o.key)<=t.length);c.length>0&&parseInt(c[c.length-1].key)<t.length&&c.push(f.cloneElement(l.current[c.length],{...l.current[c.length].props},t.slice(parseInt(c[c.length-1].key)))),l.current=c,s.current=t.length,i.current=t}else a.current=Math.random(),l.current.length>0?l.current=[f.cloneElement(l.current[0],{...l.current[0].props,key:`${t.length}-${a.current}`},t)]:l.current=[],s.current=t.length,i.current=t;n(l.current)},[t]),p.jsx(p.Fragment,{children:r})}function yt({children:t,isThinking:e}){const{showReasoningContentByDefault:r,setShowReasoningContentByDefault:n}=Mt(d=>d),[s,i]=f.useState(r!==!1),[l,a]=f.useState(0),[c,o]=f.useState(e),u=f.useRef(null);return f.useEffect(()=>{const d=new ResizeObserver(()=>{var h;a(((h=u.current)==null?void 0:h.clientHeight)||0)});return u.current&&d.observe(u.current),()=>{d.disconnect()}},[]),p.jsxs("div",{className:"mb-4 rounded-2xl md:mt-3",children:[p.jsx("div",{className:"flex",children:p.jsxs("div",{className:_("flex w-48 cursor-pointer select-none items-center gap-2 rounded-3xl p-2 pr-2 text-sm font-semibold transition-all duration-200 md:hover:bg-yellow-500/20 md:active:bg-yellow-500/30 dark:md:hover:bg-yellow-500/10 dark:md:active:bg-yellow-500/20",e&&"animate-pulse"),onClick:()=>{o(!0),i(!s)},children:[p.jsx(Te,{enableReasoning:!0})," ",e?p.jsx("span",{className:"motion-preset-slide-down-md",children:p.jsx(V,{id:"Ed99mE"})},10):s?p.jsx("span",{className:"motion-preset-slide-down-md",children:p.jsx(V,{id:"7Z1zBq"})},0):p.jsx("span",{className:"motion-preset-slide-up-md",children:p.jsx(V,{id:"7qPtNp"})},1),s?p.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"motion-preset-slide-up-md ml-auto size-5",children:p.jsx("path",{fillRule:"evenodd",d:"M9.47 6.47a.75.75 0 0 1 1.06 0l4.25 4.25a.75.75 0 1 1-1.06 1.06L10 8.06l-3.72 3.72a.75.75 0 0 1-1.06-1.06l4.25-4.25Z",clipRule:"evenodd"})},2):p.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 20 20",fill:"currentColor",className:"motion-preset-slide-down-md ml-auto size-5",children:p.jsx("path",{fillRule:"evenodd",d:"M5.22 8.22a.75.75 0 0 1 1.06 0L10 11.94l3.72-3.72a.75.75 0 1 1 1.06 1.06l-4.25 4.25a.75.75 0 0 1-1.06 0L5.22 9.28a.75.75 0 0 1 0-1.06Z",clipRule:"evenodd"})},3)]})}),p.jsx("div",{className:_("overflow-hidden",s?"opacity-100":"opacity-0",c&&"transition-[opacity,height] duration-300",c&&e&&"transition-[opacity]"),style:{height:s?l>0?`${l}px`:void 0:"0px"},children:p.jsx("div",{className:_("ml-[18px] overflow-hidden border-l pl-4 [mask-image:linear-gradient(180deg,#ffff_calc(100%_-_8px),_#0000_100%)]",c&&e&&"transition-[height] duration-300"),style:{height:l>0?`${l}px`:void 0},children:p.jsx("div",{ref:u,className:"-mt-4 text-slate-600 dark:text-zinc-400",children:t})})})]})}function rr({snippet:t,lang:e}){return p.jsx("div",{className:"group/code z-20 flex w-full flex-1 flex-col rounded-2xl bg-neutral-100 will-change-scroll dark:bg-neutral-700",children:p.jsx("div",{className:"flex w-full overflow-auto",children:p.jsx(f.Suspense,{fallback:p.jsx("pre",{className:"w-0 flex-1",children:p.jsx("code",{className:"block overflow-x-auto p-4",children:t})}),children:p.jsx(tr,{snippet:t,lang:e})})})})}function sr({children:t}){return p.jsx("span",{children:p.jsx(f.Suspense,{fallback:p.jsx("code",{children:t}),children:p.jsx(wt,{katexOptions:Et,children:t})})})}function ir({children:t}){return p.jsx("p",{children:p.jsx(f.Suspense,{fallback:p.jsx("code",{children:t}),children:p.jsx(wt,{katexOptions:Et,children:t})})})}const Et={strict:!1,throwOnError:!1,macros:{"\\f":"#1f(#2)"}},St={heading(t,e){switch(e){case 1:return p.jsx("h1",{className:"mb-2 mt-7 text-2xl font-semibold",children:t},this.elementId);case 2:return p.jsx("h2",{className:"mb-2 mt-7 text-xl font-semibold",children:t},this.elementId);case 3:return p.jsx("h3",{className:"mb-2 mt-7 text-lg font-semibold",children:t},this.elementId);case 4:return p.jsx("h4",{className:"mb-2 mt-7 font-semibold",children:t},this.elementId);case 5:return p.jsx("h5",{className:"mb-2 mt-7 font-semibold",children:t},this.elementId);case 6:return p.jsx("h6",{className:"mb-2 mt-7 font-semibold",children:t},this.elementId)}},text(t){return p.jsx(vt,{animate:!1,children:t},this.elementId)},paragraph(t){return p.jsx("p",{className:"my-4 text-base/7",children:t},this.elementId)},list(t,e,r){return e?p.jsx("ol",{start:r,className:"list-inside list-decimal",children:t},this.elementId):p.jsx("ul",{className:"list-inside list-disc",children:t},this.elementId)},listItem(t){return p.jsx("li",{className:"my-4",children:t},this.elementId)},hr(){return p.jsx("hr",{className:"border-[1px]"},this.elementId)},blockquote(t){return p.jsx("blockquote",{className:"border-l-2 pl-3",children:t},this.elementId)},codespan(t,e=null){var n;const r=e?`${(n=this.options)==null?void 0:n.langPrefix}${e}`:null;return p.jsx("code",{className:_("mx-0.5 text-wrap break-words rounded-md bg-stone-200 box-decoration-clone px-0.5 text-stone-800/90 dark:bg-neutral-700 dark:text-stone-300",r),children:t},this.elementId)},code(t,e){return p.jsx(rr,{snippet:t,lang:e},this.elementId)},inlineKatex(t){return p.jsx(sr,{children:t},this.elementId)},blockKatex(t){return p.jsx(ir,{children:t},this.elementId)},thinkBlock(t,e){return p.jsx(yt,{isThinking:!1,children:t},this.elementId)}},ar={...St,text(t){return p.jsx(vt,{animate:!0,children:t},this.elementId)},thinkBlock(t,e){return p.jsx(yt,{isThinking:e,children:t},this.elementId)}};function fr({stream:t=!1,...e}){return p.jsx(Nn,{isInline:!1,breaks:!0,gfm:!0,baseURL:void 0,openLinksInNewTab:!0,langPrefix:"language-",renderer:t?ar:St,...e,children:e.children})}function gr(t){const e={},r=[{regex:/```[\s\S]*?(```|$)/g,suffix:"\n```"},{regex:/\$\$[\s\S]*?(\$\$|$)/g,suffix:`
|
| 59 |
+
$$`},{regex:/\\\[[\s\S]*?(\\\]|$)/g,suffix:`
|
| 60 |
+
\\]`}];let n=t;n=lr(n,e,r);let s=n.split(`
|
| 61 |
+
`);return s=cr(s),n=s.join(`
|
| 62 |
+
`),n=or(n,t,e,r),n}function lr(t,e,r){let n=t;return r.forEach((s,i)=>{const{regex:l,suffix:a}=s,c=[],o=`__BLOCK_${i}_`;e[o]=c,n=n.replace(l,u=>{const h=(a?u.endsWith(a):!0)?u:u+a;return c.push(h),`${o}${c.length-1}__`})}),n}function or(t,e,r,n){let s=t;return n.forEach((i,l)=>{const{suffix:a}=i,c=`__BLOCK_${l}_`;r[c].forEach((u,d)=>{const h=u.endsWith(a)&&!e.includes(u)?u.slice(0,-1*a.length):u;s=s.replace(`${c}${d}__`,h.replace(/\$/g,"$$$$"))})}),s}function cr(t){let e=null,r=0;for(;r<t.length;){const n=t[r],s=nt(n);if(s==="empty"){r++;continue}e!==null&&(s!==e||s==="paragraph")&&r>0&&nt(t[r-1])!=="empty"&&(t.splice(r,0,""),r++),s!=="empty"&&(e=s),r++}return t}function nt(t){const e=t.trim();return e===""?"empty":/^#{1,6}\s/.test(e)?"heading":/^\d+\.\s/.test(e)||/^[-*+]\s/.test(e)?"list":/^>/.test(e)?"blockquote":/^\|/.test(e)?"table":e.startsWith("```")?"code":"paragraph"}const z={"input-range-root":"_input-range-root_2we18_3","input-range":"_input-range_2we18_3","input-range-number":"_input-range-number_2we18_12","input-text-error":"_input-text-error_2we18_79","input-list-input":"_input-list-input_2we18_85","input-list-control":"_input-list-control_2we18_93","input-list-items":"_input-list-items_2we18_101","input-list-item":"_input-list-item_2we18_101","input-list-delete":"_input-list-delete_2we18_123","input-list-edit":"_input-list-edit_2we18_134","input-list-edit-label":"_input-list-edit-label_2we18_145","input-list-counter":"_input-list-counter_2we18_149"};function mr({min:t,showMin:e=!0,max:r,showMax:n=!0,step:s,value:i,showValueWhenChange:l=!1,onChange:a,className:c,...o}){return p.jsxs("div",{className:`${z["input-range-root"]} ${c||""}`,children:[e&&p.jsx("span",{className:z["input-range-number"],children:t}),p.jsx("input",{...o,value:i,onChange:u=>a==null?void 0:a(parseFloat(u.target.value)),min:t,max:r,step:s,type:"range",className:z["input-range"]}),n&&p.jsx("span",{className:z["input-range-number"],children:r})]})}function ur({value:t,className:e,onChange:r,verification:n,ref:s,...i}){const[l,a]=f.useState(t||""),[c,o]=f.useState(!1),u=d=>{const h=d.target.value;if(a(h),n){const g=n(h);o(!g),g&&r&&r(h)}else o(!1),r&&r(h)};return f.useEffect(()=>{a(t||"")},[t]),p.jsx("input",{...i,ref:s,type:"text",className:c?`${e||""} ${z["input-text-error"]}`:e,value:l,onChange:u})}function xr({value:t,onChange:e,max:r=1/0,verification:n,className:s,classNameItem:i,classNameItemEdit:l}){const[a,c]=f.useState(""),[o,u]=f.useState(null),[d,h]=f.useState(""),g=f.useRef(null),x=f.useRef(null),S=k=>{var v;k.target===g.current&&((v=x.current)==null||v.focus())},T=k=>{if(k.key==="Enter"){k.preventDefault();const v=a.trim();v&&t.length<r&&(!n||n(v))&&(e==null||e([...t,v]),c(""))}else k.key==="Backspace"&&!a&&t.length>0&&(e==null||e(t.slice(0,-1)))},m=k=>v=>{v.dataTransfer.setData("index",k.toString())},w=k=>v=>{v.preventDefault();const L=parseInt(v.dataTransfer.getData("index"));if(L!==k){const b=[...t],[B]=b.splice(L,1);b.splice(k,0,B),e==null||e(b)}},I=()=>{if(o!==null)if(d.trim()){if(!n||n(d.trim())){const k=[...t];k[o]=d.trim(),e==null||e(k)}}else e==null||e(t.filter((k,v)=>v!==o));u(null)};return p.jsxs("div",{className:`${z["input-list-items"]} ${s||""}`,ref:g,onClick:S,children:[t.map((k,v)=>p.jsx("div",{className:`${z["input-list-item"]} ${i||""}`,draggable:o!==v,onDragStart:m(v),onDragOver:L=>L.preventDefault(),onDrop:w(v),onClick:()=>{u(v),h(k)},children:o===v?p.jsxs(p.Fragment,{children:[p.jsx("label",{className:z["input-list-edit-label"],children:d}),p.jsx("input",{type:"text",value:d,onChange:L=>h(L.target.value),onKeyDown:L=>{L.key==="Enter"?I():L.key==="Backspace"&&!d&&(e==null||e(t.filter((b,B)=>B!==o)),u(null))},onBlur:I,autoFocus:!0,className:`${z["input-list-edit"]} ${l||""}`})]}):p.jsxs(p.Fragment,{children:[p.jsx("span",{children:k}),p.jsx("button",{className:z["input-list-delete"],onClick:()=>e==null?void 0:e(t.filter((L,b)=>b!==v)),children:"×"})]})},`${t.length}-${v}`)),p.jsxs("div",{className:z["input-list-control"],children:[p.jsx(ur,{value:a,onChange:c,verification:k=>!n||n(k),onKeyDown:T,className:`${z["input-list-input"]}`,ref:x}),r<1/0&&p.jsxs("div",{className:z["input-list-counter"],children:[t.length,"/",r]})]})]})}export{Oe as C,mr as I,Hn as P,fr as R,qe as S,ur as a,xr as b,gr as c,dr as d};
|
dist/assets/KaTeX_AMS-Regular-BQhdFMY1.woff2
ADDED
|
Binary file (28.1 kB). View file
|
|
|
dist/assets/KaTeX_AMS-Regular-DMm9YOAa.woff
ADDED
|
Binary file (33.5 kB). View file
|
|
|
dist/assets/KaTeX_AMS-Regular-DRggAlZN.ttf
ADDED
|
Binary file (63.6 kB). View file
|
|
|
dist/assets/KaTeX_Caligraphic-Bold-ATXxdsX0.ttf
ADDED
|
Binary file (12.4 kB). View file
|
|
|
dist/assets/KaTeX_Caligraphic-Bold-BEiXGLvX.woff
ADDED
|
Binary file (7.72 kB). View file
|
|
|
dist/assets/KaTeX_Caligraphic-Bold-Dq_IR9rO.woff2
ADDED
|
Binary file (6.91 kB). View file
|
|
|
dist/assets/KaTeX_Caligraphic-Regular-CTRA-rTL.woff
ADDED
|
Binary file (7.66 kB). View file
|
|
|
dist/assets/KaTeX_Caligraphic-Regular-Di6jR-x-.woff2
ADDED
|
Binary file (6.91 kB). View file
|
|
|
dist/assets/KaTeX_Caligraphic-Regular-wX97UBjC.ttf
ADDED
|
Binary file (12.3 kB). View file
|
|
|
dist/assets/KaTeX_Fraktur-Bold-BdnERNNW.ttf
ADDED
|
Binary file (19.6 kB). View file
|
|
|
dist/assets/KaTeX_Fraktur-Bold-BsDP51OF.woff
ADDED
|
Binary file (13.3 kB). View file
|
|
|
dist/assets/KaTeX_Fraktur-Bold-CL6g_b3V.woff2
ADDED
|
Binary file (11.3 kB). View file
|
|
|
dist/assets/KaTeX_Fraktur-Regular-CB_wures.ttf
ADDED
|
Binary file (19.6 kB). View file
|
|
|
dist/assets/KaTeX_Fraktur-Regular-CTYiF6lA.woff2
ADDED
|
Binary file (11.3 kB). View file
|
|
|
dist/assets/KaTeX_Fraktur-Regular-Dxdc4cR9.woff
ADDED
|
Binary file (13.2 kB). View file
|
|
|
dist/assets/KaTeX_Main-Bold-Cx986IdX.woff2
ADDED
|
Binary file (25.3 kB). View file
|
|
|
dist/assets/KaTeX_Main-Bold-Jm3AIy58.woff
ADDED
|
Binary file (29.9 kB). View file
|
|
|
dist/assets/KaTeX_Main-Bold-waoOVXN0.ttf
ADDED
|
Binary file (51.3 kB). View file
|
|
|
dist/assets/KaTeX_Main-BoldItalic-DxDJ3AOS.woff2
ADDED
|
Binary file (16.8 kB). View file
|
|
|
dist/assets/KaTeX_Main-BoldItalic-DzxPMmG6.ttf
ADDED
|
Binary file (33 kB). View file
|
|
|
dist/assets/KaTeX_Main-BoldItalic-SpSLRI95.woff
ADDED
|
Binary file (19.4 kB). View file
|
|
|
dist/assets/KaTeX_Main-Italic-3WenGoN9.ttf
ADDED
|
Binary file (33.6 kB). View file
|
|
|
dist/assets/KaTeX_Main-Italic-BMLOBm91.woff
ADDED
|
Binary file (19.7 kB). View file
|
|
|
dist/assets/KaTeX_Main-Italic-NWA7e6Wa.woff2
ADDED
|
Binary file (17 kB). View file
|
|
|
dist/assets/KaTeX_Main-Regular-B22Nviop.woff2
ADDED
|
Binary file (26.3 kB). View file
|
|
|
dist/assets/KaTeX_Main-Regular-Dr94JaBh.woff
ADDED
|
Binary file (30.8 kB). View file
|
|
|
dist/assets/KaTeX_Main-Regular-ypZvNtVU.ttf
ADDED
|
Binary file (53.6 kB). View file
|
|
|
dist/assets/KaTeX_Math-BoldItalic-B3XSjfu4.ttf
ADDED
|
Binary file (31.2 kB). View file
|
|
|