Compare commits
241 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a1ed0cb2e9 | ||
|
|
5ee5fa7e6e | ||
|
|
d8c70453ec | ||
|
|
e930eb5967 | ||
|
|
aec6ad636a | ||
|
|
750c91bd3e | ||
|
|
fcc3886db1 | ||
|
|
22afc98be5 | ||
|
|
5b1a9448e6 | ||
|
|
07d89e3eeb | ||
|
|
96e97d9c1e | ||
|
|
bcb125e168 | ||
|
|
6fbb86667c | ||
|
|
2d545604f4 | ||
|
|
7210a7481e | ||
|
|
55210c89e2 | ||
|
|
c725d11dd9 | ||
|
|
ba2a6bd06c | ||
|
|
57b80c6ed0 | ||
|
|
115c59d5e1 | ||
|
|
543ff468b7 | ||
|
|
96ae47989e | ||
|
|
368932a610 | ||
|
|
f2cd531fcb | ||
|
|
511652b71c | ||
|
|
525fb132d6 | ||
|
|
5acb1fd958 | ||
|
|
76761ee453 | ||
|
|
134b2884e6 | ||
|
|
261e7c8916 | ||
|
|
987854fe49 | ||
|
|
c54d10795f | ||
|
|
b7d9ab0845 | ||
|
|
176800444a | ||
|
|
00c13cfc3f | ||
|
|
620e0228ed | ||
|
|
87ca694b0b | ||
|
|
417389c5f6 | ||
|
|
fa9f62b42c | ||
|
|
2c4e9f69eb | ||
|
|
119204368d | ||
|
|
87a86042d2 | ||
|
|
32c386799d | ||
|
|
b56a55e81d | ||
|
|
2fe7a23049 | ||
|
|
9ed3547738 | ||
|
|
a0522594da | ||
|
|
1cac147df4 | ||
|
|
db67f30082 | ||
|
|
08cf09416a | ||
|
|
7f2f4f15c1 | ||
|
|
97f6af595e | ||
|
|
447f4572b1 | ||
|
|
5c9b4a4c05 | ||
|
|
70f2271b94 | ||
|
|
15cd689741 | ||
|
|
82a68593bb | ||
|
|
21910af96a | ||
|
|
412a0fe135 | ||
|
|
cf0972ba52 | ||
|
|
3fe9ef4546 | ||
|
|
4cd5a56070 | ||
|
|
35a7437714 | ||
|
|
131a7ddf4a | ||
|
|
1465908574 | ||
|
|
3eb10f08bb | ||
|
|
b20990d380 | ||
|
|
1a5bf4a95e | ||
|
|
3d123524e7 | ||
|
|
25a41e51b3 | ||
|
|
f998ff239a | ||
|
|
bae9ae6551 | ||
|
|
285e8b1577 | ||
|
|
ce915cdf6a | ||
|
|
84317a03e8 | ||
|
|
ac1fa09604 | ||
|
|
43bc08648d | ||
|
|
e93c77394d | ||
|
|
4b2509e643 | ||
|
|
14fbb437ff | ||
|
|
8963543159 | ||
|
|
377f71b16b | ||
|
|
d32351c130 | ||
|
|
967be6f88f | ||
|
|
fcdda71b46 | ||
|
|
138251932c | ||
|
|
4d1a2396e3 | ||
|
|
b06e292989 | ||
|
|
b1d5b84dd6 | ||
|
|
2beddab114 | ||
|
|
7f85a08508 | ||
|
|
721653a812 | ||
|
|
d99488f22f | ||
|
|
21c3009945 | ||
|
|
3f77762fda | ||
|
|
9590d93c34 | ||
|
|
e0e846a191 | ||
|
|
e9cc9b0798 | ||
|
|
51c5696bb9 | ||
|
|
64f0610ed7 | ||
|
|
1591430742 | ||
|
|
17c690dfb1 | ||
|
|
4b640f884b | ||
|
|
8976764ee5 | ||
|
|
47db663fcd | ||
|
|
366e67bb6e | ||
|
|
b52bae6e17 | ||
|
|
714b8834c7 | ||
|
|
631704d04d | ||
|
|
5896593951 | ||
|
|
8431b5d24f | ||
|
|
bbd1ac1484 | ||
|
|
5990567a79 | ||
|
|
fa0fcc2c89 | ||
|
|
face4c97e8 | ||
|
|
c0ad99673b | ||
|
|
510683c57e | ||
|
|
cea1d8b4d1 | ||
|
|
b7c34b0d42 | ||
|
|
a95fbbbd78 | ||
|
|
d1560674b3 | ||
|
|
4fdfbd2f82 | ||
|
|
635767408f | ||
|
|
39a7eee8ea | ||
|
|
6ec6044901 | ||
|
|
4760a552d4 | ||
|
|
6294327273 | ||
|
|
260f51955a | ||
|
|
29ea886576 | ||
|
|
dae3f72d04 | ||
|
|
796338a32f | ||
|
|
66621e4ceb | ||
|
|
a6f5b520c3 | ||
|
|
c23c644fbc | ||
|
|
cb85c0938d | ||
|
|
88a5d11e15 | ||
|
|
1ecb0b444b | ||
|
|
72d601370d | ||
|
|
4814b88172 | ||
|
|
cfad67a922 | ||
|
|
c28f5604ab | ||
|
|
5853b8ca8d | ||
|
|
ebfc0ce672 | ||
|
|
e62fcd152a | ||
|
|
9bd9b9ecbd | ||
|
|
17faa9c5b8 | ||
|
|
4cd445bf77 | ||
|
|
4fb35845b0 | ||
|
|
f373f1caa8 | ||
|
|
4e75531651 | ||
|
|
539c538d65 | ||
|
|
d90186db33 | ||
|
|
a2d8729ae3 | ||
|
|
edc6ac7297 | ||
|
|
e89e23621c | ||
|
|
6b9ec4c6fa | ||
|
|
ced0966ffc | ||
|
|
966b912013 | ||
|
|
dc71054e61 | ||
|
|
408f3c1a4d | ||
|
|
38b775c937 | ||
|
|
f2ec1067bf | ||
|
|
b01584c49e | ||
|
|
01e56382a3 | ||
|
|
391c067250 | ||
|
|
5b98b5c0a7 | ||
|
|
5bde0abb8d | ||
|
|
1036852924 | ||
|
|
2b10ccd507 | ||
|
|
e1df1bfc3f | ||
|
|
b41a2e7039 | ||
|
|
b63370928d | ||
|
|
06a125b8d7 | ||
|
|
b03b00419b | ||
|
|
2f5a7d2d51 | ||
|
|
e318331909 | ||
|
|
796e5f22c0 | ||
|
|
b49968c145 | ||
|
|
cf16e54463 | ||
|
|
7bc8da2e29 | ||
|
|
26174d4c10 | ||
|
|
3c18ce34c7 | ||
|
|
c8b2bb53ef | ||
|
|
9f5d15a7d5 | ||
|
|
8291c50058 | ||
|
|
1f3f6cf9a8 | ||
|
|
83905c65c7 | ||
|
|
9af2b1d208 | ||
|
|
67c9381b82 | ||
|
|
4bdfa2d54c | ||
|
|
9945338458 | ||
|
|
d93157bde4 | ||
|
|
4db9b13803 | ||
|
|
69ab273706 | ||
|
|
d4ce828e99 | ||
|
|
8838b60e97 | ||
|
|
cbb249725d | ||
|
|
53b6a5ffe0 | ||
|
|
11b743aa53 | ||
|
|
a8c936a885 | ||
|
|
7fb27b927c | ||
|
|
50bee24e8c | ||
|
|
a196ce6da8 | ||
|
|
154827f367 | ||
|
|
deb9e030cb | ||
|
|
da033ab096 | ||
|
|
0fc429f5a3 | ||
|
|
142e30622e | ||
|
|
81d050d596 | ||
|
|
5e698a8312 | ||
|
|
55bb33bcbb | ||
|
|
b4efce15f4 | ||
|
|
3694ac5015 | ||
|
|
6fc5a335fb | ||
|
|
d66c30698c | ||
|
|
fecdf238c1 | ||
|
|
3e11128c9d | ||
|
|
822f2d729c | ||
|
|
a16c85b07d | ||
|
|
4e678eff6f | ||
|
|
94971bb666 | ||
|
|
b7fb8ed898 | ||
|
|
2ca8f5eba9 | ||
|
|
2431ff68e6 | ||
|
|
06e21badc0 | ||
|
|
52c3b7e9bf | ||
|
|
bd490b4fac | ||
|
|
48b09c4310 | ||
|
|
ffa90d89d1 | ||
|
|
e0781be9a9 | ||
|
|
33b21a0f5c | ||
|
|
bf5ac7efef | ||
|
|
06622b79aa | ||
|
|
537f11cbf1 | ||
|
|
c6500c6b3a | ||
|
|
6f629dbc55 | ||
|
|
5729d9fc62 | ||
|
|
bb8af451f6 | ||
|
|
ed330566e3 | ||
|
|
673ecb489e | ||
|
|
5192e31bac |
8
.gitattributes
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
backend-python/rwkv_pip/** linguist-vendored
|
||||
backend-python/wkv_cuda_utils/** linguist-vendored
|
||||
backend-python/get-pip.py linguist-vendored
|
||||
backend-python/convert_model.py linguist-vendored
|
||||
build/** linguist-vendored
|
||||
finetune/lora/** linguist-vendored
|
||||
finetune/json2binidx_tool/** linguist-vendored
|
||||
frontend/wailsjs/** linguist-generated
|
||||
123
.github/workflows/release.yml
vendored
Normal file
@@ -0,0 +1,123 @@
|
||||
name: release
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
env:
|
||||
GH_TOKEN: ${{ github.token }}
|
||||
|
||||
jobs:
|
||||
create-draft:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: master
|
||||
|
||||
- uses: jossef/action-set-json-field@v2.1
|
||||
with:
|
||||
file: manifest.json
|
||||
field: version
|
||||
value: ${{ env.VERSION }}
|
||||
|
||||
- continue-on-error: true
|
||||
run: |
|
||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||
git config --global user.name "github-actions[bot]"
|
||||
git commit -am "release ${{github.ref_name}}"
|
||||
git push
|
||||
|
||||
- run: |
|
||||
gh release create ${{github.ref_name}} -d -F CURRENT_CHANGE.md -t ${{github.ref_name}}
|
||||
|
||||
windows:
|
||||
runs-on: windows-latest
|
||||
needs: create-draft
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: master
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20.5'
|
||||
- uses: actions/setup-python@v4
|
||||
id: cp310
|
||||
with:
|
||||
python-version: '3.10'
|
||||
- uses: crazy-max/ghaction-chocolatey@v2
|
||||
with:
|
||||
args: install upx
|
||||
- run: |
|
||||
Start-BitsTransfer https://www.python.org/ftp/python/3.10.11/python-3.10.11-embed-amd64.zip ./python-3.10.11-embed-amd64.zip
|
||||
Expand-Archive ./python-3.10.11-embed-amd64.zip -DestinationPath ./py310
|
||||
$content=Get-Content "./py310/python310._pth"; $content | ForEach-Object {if ($_.ReadCount -eq 3) {"Lib\\site-packages"} else {$_}} | Set-Content ./py310/python310._pth
|
||||
./py310/python ./backend-python/get-pip.py
|
||||
./py310/python -m pip install Cython
|
||||
Copy-Item -Path "${{ steps.cp310.outputs.python-path }}/../include" -Destination "py310/include" -Recurse
|
||||
Copy-Item -Path "${{ steps.cp310.outputs.python-path }}/../libs" -Destination "py310/libs" -Recurse
|
||||
./py310/python -m pip install cyac
|
||||
go install github.com/wailsapp/wails/v2/cmd/wails@latest
|
||||
make
|
||||
Rename-Item -Path "build/bin/RWKV-Runner.exe" -NewName "RWKV-Runner_windows_x64.exe"
|
||||
|
||||
- run: gh release upload ${{github.ref_name}} build/bin/RWKV-Runner_windows_x64.exe
|
||||
|
||||
linux:
|
||||
runs-on: ubuntu-20.04
|
||||
needs: create-draft
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: master
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20.5'
|
||||
- run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install upx
|
||||
sudo apt-get install build-essential libgtk-3-dev libwebkit2gtk-4.0-dev
|
||||
go install github.com/wailsapp/wails/v2/cmd/wails@latest
|
||||
rm -rf ./backend-python/wkv_cuda_utils
|
||||
rm ./backend-python/get-pip.py
|
||||
sed -i '1,2d' ./backend-golang/wsl_not_windows.go
|
||||
rm ./backend-golang/wsl.go
|
||||
mv ./backend-golang/wsl_not_windows.go ./backend-golang/wsl.go
|
||||
make
|
||||
mv build/bin/RWKV-Runner build/bin/RWKV-Runner_linux_x64
|
||||
|
||||
- run: gh release upload ${{github.ref_name}} build/bin/RWKV-Runner_linux_x64
|
||||
|
||||
macos:
|
||||
runs-on: macos-13
|
||||
needs: create-draft
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
with:
|
||||
ref: master
|
||||
- uses: actions/setup-go@v4
|
||||
with:
|
||||
go-version: '1.20.5'
|
||||
- run: |
|
||||
go install github.com/wailsapp/wails/v2/cmd/wails@latest
|
||||
rm -rf ./backend-python/wkv_cuda_utils
|
||||
rm ./backend-python/get-pip.py
|
||||
sed -i '' '1,2d' ./backend-golang/wsl_not_windows.go
|
||||
rm ./backend-golang/wsl.go
|
||||
mv ./backend-golang/wsl_not_windows.go ./backend-golang/wsl.go
|
||||
make
|
||||
cp build/darwin/Readme_Install.txt build/bin/Readme_Install.txt
|
||||
cp build/bin/RWKV-Runner.app/Contents/MacOS/RWKV-Runner build/bin/RWKV-Runner_darwin_universal
|
||||
cd build/bin && zip -r RWKV-Runner_macos_universal.zip RWKV-Runner.app Readme_Install.txt
|
||||
|
||||
- run: gh release upload ${{github.ref_name}} build/bin/RWKV-Runner_macos_universal.zip build/bin/RWKV-Runner_darwin_universal
|
||||
|
||||
publish-release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: [ windows, linux, macos ]
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- run: gh release edit ${{github.ref_name}} --draft=false
|
||||
8
.gitignore
vendored
@@ -8,12 +8,18 @@ __pycache__
|
||||
*.bin
|
||||
/config.json
|
||||
/cache.json
|
||||
/presets.json
|
||||
/frontend/stats.html
|
||||
/frontend/package.json.md5
|
||||
/backend-python/get-pip.py
|
||||
/py310
|
||||
*.zip
|
||||
/cmd-helper.bat
|
||||
/install-py-dep.bat
|
||||
/backend-python/wkv_cuda
|
||||
*.exe
|
||||
*.old
|
||||
.DS_Store
|
||||
*.log.*
|
||||
*.log
|
||||
train_log.txt
|
||||
finetune/json2binidx_tool/data
|
||||
|
||||
19
.vscode/launch.json
vendored
@@ -10,9 +10,24 @@
|
||||
"name": "Python",
|
||||
"type": "python",
|
||||
"request": "launch",
|
||||
"program": "./backend-python/main.py",
|
||||
"program": "${workspaceFolder}/backend-python/main.py",
|
||||
"console": "integratedTerminal",
|
||||
"justMyCode": false,
|
||||
"justMyCode": false
|
||||
},
|
||||
{
|
||||
"name": "Golang",
|
||||
"type": "go",
|
||||
"request": "launch",
|
||||
"mode": "exec",
|
||||
"program": "${workspaceFolder}/build/bin/testwails.exe",
|
||||
"console": "integratedTerminal",
|
||||
"preLaunchTask": "build dev"
|
||||
},
|
||||
{
|
||||
"name": "Frontend",
|
||||
"type": "node-terminal",
|
||||
"request": "launch",
|
||||
"command": "wails dev -browser"
|
||||
}
|
||||
]
|
||||
}
|
||||
40
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build dev",
|
||||
"type": "shell",
|
||||
"options": {
|
||||
"cwd": "${workspaceFolder}",
|
||||
"env": {
|
||||
"CGO_ENABLED": "1"
|
||||
}
|
||||
},
|
||||
"osx": {
|
||||
"options": {
|
||||
"env": {
|
||||
"CGO_CFLAGS": "-mmacosx-version-min=10.13",
|
||||
"CGO_LDFLAGS": "-framework UniformTypeIdentifiers -mmacosx-version-min=10.13"
|
||||
}
|
||||
}
|
||||
},
|
||||
"windows": {
|
||||
"options": {
|
||||
"env": {
|
||||
"CGO_ENABLED": "0"
|
||||
}
|
||||
}
|
||||
},
|
||||
"command": "go",
|
||||
"args": [
|
||||
"build",
|
||||
"-tags",
|
||||
"dev",
|
||||
"-gcflags",
|
||||
"all=-N -l",
|
||||
"-o",
|
||||
"build/bin/testwails.exe"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
15
CURRENT_CHANGE.md
Normal file
@@ -0,0 +1,15 @@
|
||||
## Changes
|
||||
|
||||
- fix jsonl data when using directory as training data
|
||||
- fix loss parser
|
||||
- improve error messages for training
|
||||
- update logo
|
||||
- extra vc check
|
||||
- fix load_state_dict crash
|
||||
|
||||
## Install
|
||||
|
||||
- Windows: https://github.com/josStorer/RWKV-Runner/blob/master/build/windows/Readme_Install.txt
|
||||
- MacOS: https://github.com/josStorer/RWKV-Runner/blob/master/build/darwin/Readme_Install.txt
|
||||
- Linux: https://github.com/josStorer/RWKV-Runner/blob/master/build/linux/Readme_Install.txt
|
||||
- Server-Deploy-Examples: https://github.com/josStorer/RWKV-Runner/tree/master/deploy-examples
|
||||
11
Makefile
@@ -1,15 +1,22 @@
|
||||
ifeq ($(OS), Windows_NT)
|
||||
build: build-windows
|
||||
else
|
||||
else ifeq ($(shell uname -s), Darwin)
|
||||
build: build-macos
|
||||
else
|
||||
build: build-linux
|
||||
endif
|
||||
|
||||
build-windows:
|
||||
@echo ---- build for windows
|
||||
wails build -upx -ldflags "-s -w"
|
||||
wails build -upx -ldflags "-s -w" -platform windows/amd64
|
||||
|
||||
build-macos:
|
||||
@echo ---- build for macos
|
||||
wails build -ldflags "-s -w" -platform darwin/universal
|
||||
|
||||
build-linux:
|
||||
@echo ---- build for linux
|
||||
wails build -upx -ldflags "-s -w" -platform linux/amd64
|
||||
|
||||
dev:
|
||||
wails dev
|
||||
|
||||
96
README.md
@@ -13,9 +13,15 @@ compatible with the OpenAI API, which means that every ChatGPT client is an RWKV
|
||||
[![license][license-image]][license-url]
|
||||
[![release][release-image]][release-url]
|
||||
|
||||
English | [简体中文](README_ZH.md)
|
||||
English | [简体中文](README_ZH.md) | [日本語](README_JA.md)
|
||||
|
||||
[Preview](#Preview) | [Download][download-url]
|
||||
### Install
|
||||
|
||||
[![Windows][Windows-image]][Windows-url]
|
||||
[![MacOS][MacOS-image]][MacOS-url]
|
||||
[![Linux][Linux-image]][Linux-url]
|
||||
|
||||
[FAQs](https://github.com/josStorer/RWKV-Runner/wiki/FAQs) | [Preview](#Preview) | [Download][download-url] | [Server-Deploy-Examples](https://github.com/josStorer/RWKV-Runner/tree/master/deploy-examples)
|
||||
|
||||
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg
|
||||
|
||||
@@ -25,11 +31,25 @@ English | [简体中文](README_ZH.md)
|
||||
|
||||
[release-url]: https://github.com/josStorer/RWKV-Runner/releases/latest
|
||||
|
||||
[download-url]: https://github.com/josStorer/RWKV-Runner/releases/download/v1.0.2/RWKV-Runner_windows_x64.exe
|
||||
[download-url]: https://github.com/josStorer/RWKV-Runner/releases
|
||||
|
||||
[Windows-image]: https://img.shields.io/badge/-Windows-blue?logo=windows
|
||||
|
||||
[Windows-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/windows/Readme_Install.txt
|
||||
|
||||
[MacOS-image]: https://img.shields.io/badge/-MacOS-black?logo=apple
|
||||
|
||||
[MacOS-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/darwin/Readme_Install.txt
|
||||
|
||||
[Linux-image]: https://img.shields.io/badge/-Linux-black?logo=linux
|
||||
|
||||
[Linux-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/linux/Readme_Install.txt
|
||||
|
||||
</div>
|
||||
|
||||
#### Default configs do not enable custom CUDA kernel acceleration, but I strongly recommend that you enable it and run with int8 precision, which is much faster and consumes much less VRAM. Go to the Configs page and turn on `Use Custom CUDA kernel to Accelerate`.
|
||||
#### Default configs has enabled custom CUDA kernel acceleration, which is much faster and consumes much less VRAM. If you encounter possible compatibility issues, go to the Configs page and turn off `Use Custom CUDA kernel to Accelerate`.
|
||||
|
||||
#### If Windows Defender claims this is a virus, you can try downloading [v1.0.8](https://github.com/josStorer/RWKV-Runner/releases/tag/v1.0.8)/[v1.0.9](https://github.com/josStorer/RWKV-Runner/releases/tag/v1.0.9) and letting it update automatically to the latest version, or add it to the trusted list.
|
||||
|
||||
#### For different tasks, adjusting API parameters can achieve better results. For example, for translation tasks, you can try setting Temperature to 1 and Top_P to 0.3.
|
||||
|
||||
@@ -39,7 +59,8 @@ English | [简体中文](README_ZH.md)
|
||||
- Fully compatible with the OpenAI API, making every ChatGPT client an RWKV client. After starting the model,
|
||||
open http://127.0.0.1:8000/docs to view more details.
|
||||
- Automatic dependency installation, requiring only a lightweight executable program
|
||||
- User-friendly chat interaction interface included
|
||||
- Configs with 2G to 32G VRAM are included, works well on almost all computers
|
||||
- User-friendly chat and completion interaction interface included
|
||||
- Easy-to-understand and operate parameter configuration
|
||||
- Built-in model conversion tool
|
||||
- Built-in download management and remote model inspection
|
||||
@@ -47,18 +68,79 @@ English | [简体中文](README_ZH.md)
|
||||
- Theme switching
|
||||
- Automatic updates
|
||||
|
||||
## API Concurrency Stress Testing
|
||||
|
||||
```bash
|
||||
ab -p body.json -T application/json -c 20 -n 100 -l http://127.0.0.1:8000/chat/completions
|
||||
```
|
||||
|
||||
body.json:
|
||||
|
||||
```json
|
||||
{
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Embeddings API Example
|
||||
|
||||
If you are using langchain, just use `OpenAIEmbeddings(openai_api_base="http://127.0.0.1:8000", openai_api_key="sk-")`
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
import requests
|
||||
|
||||
|
||||
def cosine_similarity(a, b):
|
||||
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
|
||||
|
||||
|
||||
values = [
|
||||
"I am a girl",
|
||||
"我是个女孩",
|
||||
"私は女の子です",
|
||||
"广东人爱吃福建人",
|
||||
"我是个人类",
|
||||
"I am a human",
|
||||
"that dog is so cute",
|
||||
"私はねこむすめです、にゃん♪",
|
||||
"宇宙级特大事件!号外号外!"
|
||||
]
|
||||
|
||||
embeddings = []
|
||||
for v in values:
|
||||
r = requests.post("http://127.0.0.1:8000/embeddings", json={"input": v})
|
||||
embedding = r.json()["data"][0]["embedding"]
|
||||
embeddings.append(embedding)
|
||||
|
||||
compared_embedding = embeddings[0]
|
||||
|
||||
embeddings_cos_sim = [cosine_similarity(compared_embedding, e) for e in embeddings]
|
||||
|
||||
for i in np.argsort(embeddings_cos_sim)[::-1]:
|
||||
print(f"{embeddings_cos_sim[i]:.10f} - {values[i]}")
|
||||
```
|
||||
|
||||
## Todo
|
||||
|
||||
- [ ] Model training functionality
|
||||
- [x] CUDA operator int8 acceleration
|
||||
- [ ] macOS support
|
||||
- [ ] Linux support
|
||||
- [x] macOS support
|
||||
- [x] Linux support
|
||||
- [ ] Local State Cache DB
|
||||
|
||||
## Related Repositories:
|
||||
|
||||
- RWKV-4-World: https://huggingface.co/BlinkDL/rwkv-4-world/tree/main
|
||||
- RWKV-4-Raven: https://huggingface.co/BlinkDL/rwkv-4-raven/tree/main
|
||||
- ChatRWKV: https://github.com/BlinkDL/ChatRWKV
|
||||
- RWKV-LM: https://github.com/BlinkDL/RWKV-LM
|
||||
- RWKV-LM-LoRA: https://github.com/Blealtan/RWKV-LM-LoRA
|
||||
|
||||
## Preview
|
||||
|
||||
|
||||
163
README_JA.md
Normal file
@@ -0,0 +1,163 @@
|
||||
<p align="center">
|
||||
<img src="https://github.com/josStorer/RWKV-Runner/assets/13366013/d24834b0-265d-45f5-93c0-fac1e19562af">
|
||||
</p>
|
||||
|
||||
<h1 align="center">RWKV Runner</h1>
|
||||
|
||||
<div align="center">
|
||||
|
||||
このプロジェクトは、すべてを自動化することで、大規模な言語モデルを使用する際の障壁をなくすことを目的としています。必要なのは、
|
||||
わずか数メガバイトの軽量な実行プログラムだけです。さらに、このプロジェクトは OpenAI API と互換性のあるインターフェイスを提供しており、
|
||||
すべての ChatGPT クライアントは RWKV クライアントであることを意味します。
|
||||
|
||||
[![license][license-image]][license-url]
|
||||
[![release][release-image]][release-url]
|
||||
|
||||
[English](README.md) | [简体中文](README_ZH.md) | 日本語
|
||||
|
||||
### インストール
|
||||
|
||||
[![Windows][Windows-image]][Windows-url]
|
||||
[![MacOS][MacOS-image]][MacOS-url]
|
||||
[![Linux][Linux-image]][Linux-url]
|
||||
|
||||
[FAQs](https://github.com/josStorer/RWKV-Runner/wiki/FAQs) | [プレビュー](#Preview) | [ダウンロード][download-url] | [サーバーデプロイ例](https://github.com/josStorer/RWKV-Runner/tree/master/deploy-examples)
|
||||
|
||||
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg
|
||||
[license-url]: https://github.com/josStorer/RWKV-Runner/blob/master/LICENSE
|
||||
[release-image]: https://img.shields.io/github/release/josStorer/RWKV-Runner.svg
|
||||
[release-url]: https://github.com/josStorer/RWKV-Runner/releases/latest
|
||||
[download-url]: https://github.com/josStorer/RWKV-Runner/releases
|
||||
[Windows-image]: https://img.shields.io/badge/-Windows-blue?logo=windows
|
||||
[Windows-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/windows/Readme_Install.txt
|
||||
[MacOS-image]: https://img.shields.io/badge/-MacOS-black?logo=apple
|
||||
[MacOS-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/darwin/Readme_Install.txt
|
||||
[Linux-image]: https://img.shields.io/badge/-Linux-black?logo=linux
|
||||
[Linux-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/linux/Readme_Install.txt
|
||||
|
||||
</div>
|
||||
|
||||
#### デフォルトの設定はカスタム CUDA カーネルアクセラレーションを有効にしています。互換性の問題が発生する可能性がある場合は、コンフィグページに移動し、`Use Custom CUDA kernel to Accelerate` をオフにしてください。
|
||||
|
||||
#### Windows Defender がこれをウイルスだと主張する場合は、[v1.0.8](https://github.com/josStorer/RWKV-Runner/releases/tag/v1.0.8) / [v1.0.9](https://github.com/josStorer/RWKV-Runner/releases/tag/v1.0.9) をダウンロードして最新版に自動更新させるか、信頼済みリストに追加してみてください。
|
||||
|
||||
#### 異なるタスクについては、API パラメータを調整することで、より良い結果を得ることができます。例えば、翻訳タスクの場合、Temperature を 1 に、Top_P を 0.3 に設定してみてください。
|
||||
|
||||
## 特徴
|
||||
|
||||
- RWKV モデル管理とワンクリック起動
|
||||
- OpenAI API と完全に互換性があり、すべての ChatGPT クライアントを RWKV クライアントにします。モデル起動後、
|
||||
http://127.0.0.1:8000/docs を開いて詳細をご覧ください。
|
||||
- 依存関係の自動インストールにより、軽量な実行プログラムのみを必要とします
|
||||
- 2G から 32G の VRAM のコンフィグが含まれており、ほとんどのコンピュータで動作します
|
||||
- ユーザーフレンドリーなチャットと完成インタラクションインターフェースを搭載
|
||||
- 分かりやすく操作しやすいパラメータ設定
|
||||
- 内蔵モデル変換ツール
|
||||
- ダウンロード管理とリモートモデル検査機能内蔵
|
||||
- 多言語ローカライズ
|
||||
- テーマ切り替え
|
||||
- 自動アップデート
|
||||
|
||||
## API 同時実行ストレステスト
|
||||
|
||||
```bash
|
||||
ab -p body.json -T application/json -c 20 -n 100 -l http://127.0.0.1:8000/chat/completions
|
||||
```
|
||||
|
||||
body.json:
|
||||
|
||||
```json
|
||||
{
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## 埋め込み API の例
|
||||
|
||||
LangChain を使用している場合は、`OpenAIEmbeddings(openai_api_base="http://127.0.0.1:8000", openai_api_key="sk-")`を使用してください
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
import requests
|
||||
|
||||
|
||||
def cosine_similarity(a, b):
|
||||
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
|
||||
|
||||
|
||||
values = [
|
||||
"I am a girl",
|
||||
"我是个女孩",
|
||||
"私は女の子です",
|
||||
"广东人爱吃福建人",
|
||||
"我是个人类",
|
||||
"I am a human",
|
||||
"that dog is so cute",
|
||||
"私はねこむすめです、にゃん♪",
|
||||
"宇宙级特大事件!号外号外!"
|
||||
]
|
||||
|
||||
embeddings = []
|
||||
for v in values:
|
||||
r = requests.post("http://127.0.0.1:8000/embeddings", json={"input": v})
|
||||
embedding = r.json()["data"][0]["embedding"]
|
||||
embeddings.append(embedding)
|
||||
|
||||
compared_embedding = embeddings[0]
|
||||
|
||||
embeddings_cos_sim = [cosine_similarity(compared_embedding, e) for e in embeddings]
|
||||
|
||||
for i in np.argsort(embeddings_cos_sim)[::-1]:
|
||||
print(f"{embeddings_cos_sim[i]:.10f} - {values[i]}")
|
||||
```
|
||||
|
||||
## Todo
|
||||
|
||||
- [ ] モデル学習機能
|
||||
- [x] CUDA オペレータ int8 アクセラレーション
|
||||
- [x] macOS サポート
|
||||
- [x] Linux サポート
|
||||
- [ ] ローカルステートキャッシュ DB
|
||||
|
||||
## 関連リポジトリ:
|
||||
|
||||
- RWKV-4-World: https://huggingface.co/BlinkDL/rwkv-4-world/tree/main
|
||||
- RWKV-4-Raven: https://huggingface.co/BlinkDL/rwkv-4-raven/tree/main
|
||||
- ChatRWKV: https://github.com/BlinkDL/ChatRWKV
|
||||
- RWKV-LM: https://github.com/BlinkDL/RWKV-LM
|
||||
- RWKV-LM-LoRA: https://github.com/Blealtan/RWKV-LM-LoRA
|
||||
|
||||
## プレビュー
|
||||
|
||||
### ホームページ
|
||||
|
||||

|
||||
|
||||
### チャット
|
||||
|
||||

|
||||
|
||||
### 補完
|
||||
|
||||

|
||||
|
||||
### コンフィグ
|
||||
|
||||

|
||||
|
||||
### モデル管理
|
||||
|
||||

|
||||
|
||||
### ダウンロード管理
|
||||
|
||||

|
||||
|
||||
### 設定
|
||||
|
||||

|
||||
98
README_ZH.md
@@ -12,9 +12,15 @@ API兼容的接口,这意味着一切ChatGPT客户端都是RWKV客户端。
|
||||
[![license][license-image]][license-url]
|
||||
[![release][release-image]][release-url]
|
||||
|
||||
[English](README.md) | 简体中文
|
||||
[English](README.md) | 简体中文 | [日本語](README_JA.md)
|
||||
|
||||
[视频演示](https://www.bilibili.com/video/BV1hM4y1v76R) | [预览](#Preview) | [下载][download-url]
|
||||
### 安装
|
||||
|
||||
[![Windows][Windows-image]][Windows-url]
|
||||
[![MacOS][MacOS-image]][MacOS-url]
|
||||
[![Linux][Linux-image]][Linux-url]
|
||||
|
||||
[视频演示](https://www.bilibili.com/video/BV1hM4y1v76R) | [疑难解答](https://www.bilibili.com/read/cv23921171) | [预览](#Preview) | [下载][download-url] | [懒人包](https://pan.baidu.com/s/1wchIUHgne3gncIiLIeKBEQ?pwd=1111) | [服务器部署示例](https://github.com/josStorer/RWKV-Runner/tree/master/deploy-examples)
|
||||
|
||||
[license-image]: http://img.shields.io/badge/license-MIT-blue.svg
|
||||
|
||||
@@ -24,13 +30,27 @@ API兼容的接口,这意味着一切ChatGPT客户端都是RWKV客户端。
|
||||
|
||||
[release-url]: https://github.com/josStorer/RWKV-Runner/releases/latest
|
||||
|
||||
[download-url]: https://github.com/josStorer/RWKV-Runner/releases/download/v1.0.2/RWKV-Runner_windows_x64.exe
|
||||
[download-url]: https://github.com/josStorer/RWKV-Runner/releases
|
||||
|
||||
[Windows-image]: https://img.shields.io/badge/-Windows-blue?logo=windows
|
||||
|
||||
[Windows-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/windows/Readme_Install.txt
|
||||
|
||||
[MacOS-image]: https://img.shields.io/badge/-MacOS-black?logo=apple
|
||||
|
||||
[MacOS-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/darwin/Readme_Install.txt
|
||||
|
||||
[Linux-image]: https://img.shields.io/badge/-Linux-black?logo=linux
|
||||
|
||||
[Linux-url]: https://github.com/josStorer/RWKV-Runner/blob/master/build/linux/Readme_Install.txt
|
||||
|
||||
</div>
|
||||
|
||||
#### 注意 目前RWKV中文模型质量一般,推荐使用英文模型体验实际RWKV能力
|
||||
#### 注意 目前RWKV中文模型质量一般,推荐使用英文模型或World(全球语言)体验实际RWKV能力
|
||||
|
||||
#### 预设配置没有开启自定义CUDA算子加速,但我强烈建议你开启它并使用int8量化运行,速度非常快,且显存消耗少得多。前往配置页面,打开`使用自定义CUDA算子加速`
|
||||
#### 预设配置已经开启自定义CUDA算子加速,速度更快,且显存消耗更少。如果你遇到可能的兼容性问题,前往配置页面,关闭`使用自定义CUDA算子加速`
|
||||
|
||||
#### 如果Windows Defender说这是一个病毒,你可以尝试下载[v1.0.8](https://github.com/josStorer/RWKV-Runner/releases/tag/v1.0.8)/[v1.0.9](https://github.com/josStorer/RWKV-Runner/releases/tag/v1.0.9)然后让其自动更新到最新版,或添加信任
|
||||
|
||||
#### 对于不同的任务,调整API参数会获得更好的效果,例如对于翻译任务,你可以尝试设置Temperature为1,Top_P为0.3
|
||||
|
||||
@@ -39,7 +59,8 @@ API兼容的接口,这意味着一切ChatGPT客户端都是RWKV客户端。
|
||||
- RWKV模型管理,一键启动
|
||||
- 与OpenAI API完全兼容,一切ChatGPT客户端,都是RWKV客户端。启动模型后,打开 http://127.0.0.1:8000/docs 查看详细内容
|
||||
- 全自动依赖安装,你只需要一个轻巧的可执行程序
|
||||
- 自带用户友好的聊天交互页面
|
||||
- 预设了2G至32G显存的配置,几乎在各种电脑上工作良好
|
||||
- 自带用户友好的聊天和补全交互页面
|
||||
- 易于理解和操作的参数配置
|
||||
- 内置模型转换工具
|
||||
- 内置下载管理和远程模型检视
|
||||
@@ -47,18 +68,79 @@ API兼容的接口,这意味着一切ChatGPT客户端都是RWKV客户端。
|
||||
- 主题切换
|
||||
- 自动更新
|
||||
|
||||
## API并发压力测试
|
||||
|
||||
```bash
|
||||
ab -p body.json -T application/json -c 20 -n 100 -l http://127.0.0.1:8000/chat/completions
|
||||
```
|
||||
|
||||
body.json:
|
||||
|
||||
```json
|
||||
{
|
||||
"messages": [
|
||||
{
|
||||
"role": "user",
|
||||
"content": "Hello"
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
|
||||
## Embeddings API 示例
|
||||
|
||||
如果你在用langchain, 直接使用 `OpenAIEmbeddings(openai_api_base="http://127.0.0.1:8000", openai_api_key="sk-")`
|
||||
|
||||
```python
|
||||
import numpy as np
|
||||
import requests
|
||||
|
||||
|
||||
def cosine_similarity(a, b):
|
||||
return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))
|
||||
|
||||
|
||||
values = [
|
||||
"I am a girl",
|
||||
"我是个女孩",
|
||||
"私は女の子です",
|
||||
"广东人爱吃福建人",
|
||||
"我是个人类",
|
||||
"I am a human",
|
||||
"that dog is so cute",
|
||||
"私はねこむすめです、にゃん♪",
|
||||
"宇宙级特大事件!号外号外!"
|
||||
]
|
||||
|
||||
embeddings = []
|
||||
for v in values:
|
||||
r = requests.post("http://127.0.0.1:8000/embeddings", json={"input": v})
|
||||
embedding = r.json()["data"][0]["embedding"]
|
||||
embeddings.append(embedding)
|
||||
|
||||
compared_embedding = embeddings[0]
|
||||
|
||||
embeddings_cos_sim = [cosine_similarity(compared_embedding, e) for e in embeddings]
|
||||
|
||||
for i in np.argsort(embeddings_cos_sim)[::-1]:
|
||||
print(f"{embeddings_cos_sim[i]:.10f} - {values[i]}")
|
||||
```
|
||||
|
||||
## Todo
|
||||
|
||||
- [ ] 模型训练功能
|
||||
- [x] CUDA算子int8提速
|
||||
- [ ] macOS支持
|
||||
- [ ] linux支持
|
||||
- [x] macOS支持
|
||||
- [x] linux支持
|
||||
- [ ] 本地状态缓存数据库
|
||||
|
||||
## 相关仓库:
|
||||
|
||||
- RWKV-4-World: https://huggingface.co/BlinkDL/rwkv-4-world/tree/main
|
||||
- RWKV-4-Raven: https://huggingface.co/BlinkDL/rwkv-4-raven/tree/main
|
||||
- ChatRWKV: https://github.com/BlinkDL/ChatRWKV
|
||||
- RWKV-LM: https://github.com/BlinkDL/RWKV-LM
|
||||
- RWKV-LM-LoRA: https://github.com/Blealtan/RWKV-LM-LoRA
|
||||
|
||||
## Preview
|
||||
|
||||
|
||||
@@ -2,18 +2,25 @@ package backend_golang
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/minio/selfupdate"
|
||||
wruntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
// App struct
|
||||
type App struct {
|
||||
ctx context.Context
|
||||
ctx context.Context
|
||||
HasConfigData bool
|
||||
ConfigData map[string]any
|
||||
exDir string
|
||||
cmdPrefix string
|
||||
}
|
||||
|
||||
// NewApp creates a new App application struct
|
||||
@@ -25,8 +32,45 @@ func NewApp() *App {
|
||||
// so we can call the runtime methods
|
||||
func (a *App) OnStartup(ctx context.Context) {
|
||||
a.ctx = ctx
|
||||
a.exDir = ""
|
||||
a.cmdPrefix = ""
|
||||
|
||||
if runtime.GOOS == "darwin" {
|
||||
ex, _ := os.Executable()
|
||||
a.exDir = filepath.Dir(ex) + "/../../../"
|
||||
a.cmdPrefix = "cd " + a.exDir + " && "
|
||||
}
|
||||
|
||||
os.Mkdir(a.exDir+"models", os.ModePerm)
|
||||
os.Mkdir(a.exDir+"lora-models", os.ModePerm)
|
||||
os.Mkdir(a.exDir+"finetune/json2binidx_tool/data", os.ModePerm)
|
||||
f, err := os.Create(a.exDir + "lora-models/train_log.txt")
|
||||
if err == nil {
|
||||
f.Close()
|
||||
}
|
||||
|
||||
a.downloadLoop()
|
||||
|
||||
watcher, err := fsnotify.NewWatcher()
|
||||
if err == nil {
|
||||
watcher.Add("./lora-models")
|
||||
watcher.Add("./models")
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case event, ok := <-watcher.Events:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
wruntime.EventsEmit(ctx, "fsnotify", event.Name)
|
||||
case _, ok := <-watcher.Errors:
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) UpdateApp(url string) (broken bool, err error) {
|
||||
@@ -42,15 +86,30 @@ func (a *App) UpdateApp(url string) (broken bool, err error) {
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
name, err := os.Executable()
|
||||
if err != nil {
|
||||
return false, err
|
||||
if runtime.GOOS == "windows" {
|
||||
name, err := os.Executable()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
exec.Command(name, os.Args[1:]...).Start()
|
||||
wruntime.Quit(a.ctx)
|
||||
}
|
||||
exec.Command(name, os.Args[1:]...).Start()
|
||||
wruntime.Quit(a.ctx)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (a *App) RestartApp() error {
|
||||
if runtime.GOOS == "windows" {
|
||||
name, err := os.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exec.Command(name, os.Args[1:]...).Start()
|
||||
wruntime.Quit(a.ctx)
|
||||
return nil
|
||||
}
|
||||
return errors.New("unsupported OS")
|
||||
}
|
||||
|
||||
func (a *App) GetPlatform() string {
|
||||
return runtime.GOOS
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package backend_golang
|
||||
|
||||
import (
|
||||
"context"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
@@ -9,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func (a *App) DownloadFile(path string, url string) error {
|
||||
_, err := grab.Get(path, url)
|
||||
_, err := grab.Get(a.exDir+path, url)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -18,6 +19,7 @@ func (a *App) DownloadFile(path string, url string) error {
|
||||
|
||||
type DownloadStatus struct {
|
||||
resp *grab.Response
|
||||
cancel context.CancelFunc
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
Url string `json:"url"`
|
||||
@@ -29,7 +31,7 @@ type DownloadStatus struct {
|
||||
Done bool `json:"done"`
|
||||
}
|
||||
|
||||
var downloadList []DownloadStatus
|
||||
var downloadList []*DownloadStatus
|
||||
|
||||
func existsInDownloadList(url string) bool {
|
||||
for _, ds := range downloadList {
|
||||
@@ -41,49 +43,58 @@ func existsInDownloadList(url string) bool {
|
||||
}
|
||||
|
||||
func (a *App) PauseDownload(url string) {
|
||||
for i, ds := range downloadList {
|
||||
for _, ds := range downloadList {
|
||||
if ds.Url == url {
|
||||
if ds.resp != nil {
|
||||
ds.resp.Cancel()
|
||||
}
|
||||
|
||||
downloadList[i] = DownloadStatus{
|
||||
resp: ds.resp,
|
||||
Name: ds.Name,
|
||||
Path: ds.Path,
|
||||
Url: ds.Url,
|
||||
Downloading: false,
|
||||
if ds.cancel != nil {
|
||||
ds.cancel()
|
||||
}
|
||||
ds.resp = nil
|
||||
ds.Downloading = false
|
||||
ds.Speed = 0
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) ContinueDownload(url string) {
|
||||
for i, ds := range downloadList {
|
||||
for _, ds := range downloadList {
|
||||
if ds.Url == url {
|
||||
client := grab.NewClient()
|
||||
req, _ := grab.NewRequest(ds.Path, ds.Url)
|
||||
resp := client.Do(req)
|
||||
if !ds.Downloading && ds.resp == nil && !ds.Done {
|
||||
ds.Downloading = true
|
||||
|
||||
downloadList[i] = DownloadStatus{
|
||||
resp: resp,
|
||||
Name: ds.Name,
|
||||
Path: ds.Path,
|
||||
Url: ds.Url,
|
||||
Downloading: true,
|
||||
req, err := grab.NewRequest(ds.Path, ds.Url)
|
||||
if err != nil {
|
||||
ds.Downloading = false
|
||||
break
|
||||
}
|
||||
// if PauseDownload() is called before the request finished, ds.Downloading will be false
|
||||
// if the user keeps clicking pause and resume, it may result in multiple requests being successfully downloaded at the same time
|
||||
// so we have to create a context and cancel it when PauseDownload() is called
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ds.cancel = cancel
|
||||
req = req.WithContext(ctx)
|
||||
resp := grab.DefaultClient.Do(req)
|
||||
|
||||
if resp != nil && resp.HTTPResponse != nil &&
|
||||
resp.HTTPResponse.StatusCode >= 200 && resp.HTTPResponse.StatusCode < 300 {
|
||||
ds.resp = resp
|
||||
} else {
|
||||
ds.Downloading = false
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) AddToDownloadList(path string, url string) {
|
||||
if !existsInDownloadList(url) {
|
||||
downloadList = append(downloadList, DownloadStatus{
|
||||
downloadList = append(downloadList, &DownloadStatus{
|
||||
resp: nil,
|
||||
Name: filepath.Base(path),
|
||||
Path: path,
|
||||
Path: a.exDir + path,
|
||||
Url: url,
|
||||
Downloading: true,
|
||||
Downloading: false,
|
||||
})
|
||||
a.ContinueDownload(url)
|
||||
} else {
|
||||
@@ -96,32 +107,17 @@ func (a *App) downloadLoop() {
|
||||
go func() {
|
||||
for {
|
||||
<-ticker.C
|
||||
for i, ds := range downloadList {
|
||||
transferred := int64(0)
|
||||
size := int64(0)
|
||||
speed := float64(0)
|
||||
progress := float64(0)
|
||||
downloading := ds.Downloading
|
||||
done := false
|
||||
for _, ds := range downloadList {
|
||||
if ds.resp != nil {
|
||||
transferred = ds.resp.BytesComplete()
|
||||
size = ds.resp.Size()
|
||||
speed = ds.resp.BytesPerSecond()
|
||||
progress = 100 * ds.resp.Progress()
|
||||
downloading = !ds.resp.IsComplete()
|
||||
done = ds.resp.Progress() == 1
|
||||
}
|
||||
downloadList[i] = DownloadStatus{
|
||||
resp: ds.resp,
|
||||
Name: ds.Name,
|
||||
Path: ds.Path,
|
||||
Url: ds.Url,
|
||||
Transferred: transferred,
|
||||
Size: size,
|
||||
Speed: speed,
|
||||
Progress: progress,
|
||||
Downloading: downloading,
|
||||
Done: done,
|
||||
ds.Transferred = ds.resp.BytesComplete()
|
||||
ds.Size = ds.resp.Size()
|
||||
ds.Speed = ds.resp.BytesPerSecond()
|
||||
ds.Progress = 100 * ds.resp.Progress()
|
||||
ds.Downloading = !ds.resp.IsComplete()
|
||||
ds.Done = ds.resp.Progress() == 1
|
||||
if !ds.Downloading {
|
||||
ds.resp = nil
|
||||
}
|
||||
}
|
||||
}
|
||||
runtime.EventsEmit(a.ctx, "downloadList", downloadList)
|
||||
|
||||
@@ -2,13 +2,16 @@ package backend_golang
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
wruntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
func (a *App) SaveJson(fileName string, jsonData any) error {
|
||||
@@ -17,14 +20,14 @@ func (a *App) SaveJson(fileName string, jsonData any) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.WriteFile(fileName, text, 0644); err != nil {
|
||||
if err := os.WriteFile(a.exDir+fileName, text, 0644); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) ReadJson(fileName string) (any, error) {
|
||||
file, err := os.ReadFile(fileName)
|
||||
file, err := os.ReadFile(a.exDir + fileName)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -39,7 +42,7 @@ func (a *App) ReadJson(fileName string) (any, error) {
|
||||
}
|
||||
|
||||
func (a *App) FileExists(fileName string) bool {
|
||||
_, err := os.Stat(fileName)
|
||||
_, err := os.Stat(a.exDir + fileName)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
@@ -51,7 +54,7 @@ type FileInfo struct {
|
||||
}
|
||||
|
||||
func (a *App) ReadFileInfo(fileName string) (FileInfo, error) {
|
||||
info, err := os.Stat(fileName)
|
||||
info, err := os.Stat(a.exDir + fileName)
|
||||
if err != nil {
|
||||
return FileInfo{}, err
|
||||
}
|
||||
@@ -64,7 +67,7 @@ func (a *App) ReadFileInfo(fileName string) (FileInfo, error) {
|
||||
}
|
||||
|
||||
func (a *App) ListDirFiles(dirPath string) ([]FileInfo, error) {
|
||||
files, err := os.ReadDir(dirPath)
|
||||
files, err := os.ReadDir(a.exDir + dirPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -86,7 +89,7 @@ func (a *App) ListDirFiles(dirPath string) ([]FileInfo, error) {
|
||||
}
|
||||
|
||||
func (a *App) DeleteFile(path string) error {
|
||||
err := os.Remove(path)
|
||||
err := os.Remove(a.exDir + path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -94,13 +97,18 @@ func (a *App) DeleteFile(path string) error {
|
||||
}
|
||||
|
||||
func (a *App) CopyFile(src string, dst string) error {
|
||||
sourceFile, err := os.Open(src)
|
||||
sourceFile, err := os.Open(a.exDir + src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer sourceFile.Close()
|
||||
|
||||
destFile, err := os.Create(dst)
|
||||
err = os.MkdirAll(a.exDir+dst[:strings.LastIndex(dst, "/")], 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
destFile, err := os.Create(a.exDir + dst)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -113,8 +121,34 @@ func (a *App) CopyFile(src string, dst string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) OpenFileFolder(path string) error {
|
||||
absPath, err := filepath.Abs(path)
|
||||
func (a *App) OpenSaveFileDialog(filterPattern string, defaultFileName string, savedContent string) (string, error) {
|
||||
path, err := wruntime.SaveFileDialog(a.ctx, wruntime.SaveDialogOptions{
|
||||
DefaultFilename: defaultFileName,
|
||||
Filters: []wruntime.FileFilter{{
|
||||
Pattern: filterPattern,
|
||||
}},
|
||||
CanCreateDirectories: true,
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if path == "" {
|
||||
return "", nil
|
||||
}
|
||||
if err := os.WriteFile(path, []byte(savedContent), 0644); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
||||
func (a *App) OpenFileFolder(path string, relative bool) error {
|
||||
var absPath string
|
||||
var err error
|
||||
if relative {
|
||||
absPath, err = filepath.Abs(a.exDir + path)
|
||||
} else {
|
||||
absPath, err = filepath.Abs(path)
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -125,10 +159,21 @@ func (a *App) OpenFileFolder(path string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case "darwin":
|
||||
fmt.Println("Running on macOS")
|
||||
cmd := exec.Command("open", "-R", absPath)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case "linux":
|
||||
fmt.Println("Running on Linux")
|
||||
cmd := exec.Command("xdg-open", absPath)
|
||||
err := cmd.Run()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
return errors.New("unsupported OS")
|
||||
}
|
||||
|
||||
@@ -1,60 +1,157 @@
|
||||
package backend_golang
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (a *App) StartServer(port int, host string) (string, error) {
|
||||
python, err := GetPython()
|
||||
func (a *App) StartServer(python string, port int, host string) (string, error) {
|
||||
var err error
|
||||
if python == "" {
|
||||
python, err = GetPython()
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return Cmd(python, "./backend-python/main.py", strconv.Itoa(port), host)
|
||||
}
|
||||
|
||||
func (a *App) ConvertModel(modelPath string, strategy string, outPath string) (string, error) {
|
||||
python, err := GetPython()
|
||||
func (a *App) ConvertModel(python string, modelPath string, strategy string, outPath string) (string, error) {
|
||||
var err error
|
||||
if python == "" {
|
||||
python, err = GetPython()
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return Cmd(python, "./backend-python/convert_model.py", "--in", modelPath, "--out", outPath, "--strategy", strategy)
|
||||
}
|
||||
|
||||
func (a *App) DepCheck() error {
|
||||
python, err := GetPython()
|
||||
func (a *App) ConvertData(python string, input string, outputPrefix string, vocab string) (string, error) {
|
||||
var err error
|
||||
if python == "" {
|
||||
python, err = GetPython()
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
tokenizerType := "HFTokenizer"
|
||||
if strings.Contains(vocab, "rwkv_vocab_v20230424") {
|
||||
tokenizerType = "RWKVTokenizer"
|
||||
}
|
||||
|
||||
input = strings.TrimSuffix(input, "/")
|
||||
if fi, err := os.Stat(input); err == nil && fi.IsDir() {
|
||||
files, err := os.ReadDir(input)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
jsonlFile, err := os.Create(outputPrefix + ".jsonl")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer jsonlFile.Close()
|
||||
for _, file := range files {
|
||||
if file.IsDir() || !strings.HasSuffix(file.Name(), ".txt") {
|
||||
continue
|
||||
}
|
||||
textContent, err := os.ReadFile(input + "/" + file.Name())
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
textJson, err := json.Marshal(map[string]string{"text": string(textContent)})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if _, err := jsonlFile.WriteString(string(textJson) + "\n"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
input = outputPrefix + ".jsonl"
|
||||
} else if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return Cmd(python, "./finetune/json2binidx_tool/tools/preprocess_data.py", "--input", input, "--output-prefix", outputPrefix, "--vocab", vocab,
|
||||
"--tokenizer-type", tokenizerType, "--dataset-impl", "mmap", "--append-eod")
|
||||
}
|
||||
|
||||
func (a *App) MergeLora(python string, useGpu bool, loraAlpha int, baseModel string, loraPath string, outputPath string) (string, error) {
|
||||
var err error
|
||||
if python == "" {
|
||||
python, err = GetPython()
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
args := []string{python, "./finetune/lora/merge_lora.py"}
|
||||
if useGpu {
|
||||
args = append(args, "--use-gpu")
|
||||
}
|
||||
args = append(args, strconv.Itoa(loraAlpha), baseModel, loraPath, outputPath)
|
||||
return Cmd(args...)
|
||||
}
|
||||
|
||||
func (a *App) DepCheck(python string) error {
|
||||
var err error
|
||||
if python == "" {
|
||||
python, err = GetPython()
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
out, err := exec.Command(python, "./backend-python/dep_check.py").CombinedOutput()
|
||||
out, err := exec.Command(python, a.exDir+"./backend-python/dep_check.py").CombinedOutput()
|
||||
if err != nil {
|
||||
return errors.New("DepCheck Error: " + string(out))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) InstallPyDep(cnMirror bool) (string, error) {
|
||||
python, err := GetPython()
|
||||
func (a *App) InstallPyDep(python string, cnMirror bool) (string, error) {
|
||||
var err error
|
||||
if python == "" {
|
||||
python, err = GetPython()
|
||||
if runtime.GOOS == "windows" {
|
||||
python = `"%CD%/` + python + `"`
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
ChangeFileLine("./py310/python310._pth", 3, "Lib\\site-packages")
|
||||
installScript := python + " ./backend-python/get-pip.py -i https://pypi.tuna.tsinghua.edu.cn/simple\n" +
|
||||
python + " -m pip install torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 --index-url https://download.pytorch.org/whl/cu117\n" +
|
||||
python + " -m pip install -r ./backend-python/requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple\n" +
|
||||
"exit"
|
||||
if !cnMirror {
|
||||
installScript = strings.Replace(installScript, " -i https://pypi.tuna.tsinghua.edu.cn/simple", "", -1)
|
||||
installScript = strings.Replace(installScript, "requirements.txt", "requirements_versions.txt", -1)
|
||||
}
|
||||
err = os.WriteFile("./install-py-dep.bat", []byte(installScript), 0644)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return Cmd("install-py-dep.bat")
|
||||
}
|
||||
|
||||
if cnMirror {
|
||||
_, err = Cmd(python, "./backend-python/get-pip.py", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
|
||||
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_without_cyac.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
|
||||
} else {
|
||||
_, err = Cmd(python, "./backend-python/get-pip.py")
|
||||
}
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
ChangeFileLine("./py310/python310._pth", 3, "Lib\\site-packages")
|
||||
_, err = Cmd(python, "-m", "pip", "install", "torch==1.13.1", "torchvision==0.14.1", "torchaudio==0.13.1", "--index-url", "https://download.pytorch.org/whl/cu117")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
if cnMirror {
|
||||
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements.txt", "-i", "https://pypi.tuna.tsinghua.edu.cn/simple")
|
||||
} else {
|
||||
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_versions.txt")
|
||||
return Cmd(python, "-m", "pip", "install", "-r", "./backend-python/requirements_without_cyac.txt")
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) GetPyError() string {
|
||||
content, err := os.ReadFile("./error.txt")
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return string(content)
|
||||
}
|
||||
|
||||
@@ -3,8 +3,10 @@ package backend_golang
|
||||
import (
|
||||
"archive/zip"
|
||||
"bufio"
|
||||
"embed"
|
||||
"errors"
|
||||
"io"
|
||||
"io/fs"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
@@ -13,22 +15,91 @@ import (
|
||||
)
|
||||
|
||||
func Cmd(args ...string) (string, error) {
|
||||
_, err := os.Stat("cmd-helper.bat")
|
||||
if err != nil {
|
||||
switch platform := runtime.GOOS; platform {
|
||||
case "windows":
|
||||
if err := os.WriteFile("./cmd-helper.bat", []byte("start %*"), 0644); err != nil {
|
||||
return "", err
|
||||
}
|
||||
cmdHelper, err := filepath.Abs("./cmd-helper")
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
if strings.Contains(cmdHelper, " ") {
|
||||
for _, arg := range args {
|
||||
if strings.Contains(arg, " ") {
|
||||
return "", errors.New("path contains space") // golang bug https://github.com/golang/go/issues/17149#issuecomment-473976818
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cmd := exec.Command(cmdHelper, args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(out), nil
|
||||
case "darwin":
|
||||
ex, err := os.Executable()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
exDir := filepath.Dir(ex) + "/../../../"
|
||||
cmd := exec.Command("osascript", "-e", `tell application "Terminal" to do script "`+"cd "+exDir+" && "+strings.Join(args, " ")+`"`)
|
||||
err = cmd.Start()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
cmd.Wait()
|
||||
return "", nil
|
||||
case "linux":
|
||||
cmd := exec.Command(args[0], args[1:]...)
|
||||
err := cmd.Start()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
cmd.Wait()
|
||||
return "", nil
|
||||
}
|
||||
cmdHelper, err := filepath.Abs("./cmd-helper")
|
||||
if err != nil {
|
||||
return "", err
|
||||
return "", errors.New("unsupported OS")
|
||||
}
|
||||
|
||||
func CopyEmbed(efs embed.FS) error {
|
||||
prefix := ""
|
||||
if runtime.GOOS == "darwin" {
|
||||
ex, err := os.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prefix = filepath.Dir(ex) + "/../../../"
|
||||
}
|
||||
cmd := exec.Command(cmdHelper, args...)
|
||||
out, err := cmd.CombinedOutput()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return string(out), nil
|
||||
|
||||
err := fs.WalkDir(efs, ".", func(path string, d fs.DirEntry, err error) error {
|
||||
if d.IsDir() {
|
||||
return nil
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
content, err := efs.ReadFile(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
path = prefix + path
|
||||
err = os.MkdirAll(path[:strings.LastIndex(path, "/")], 0755)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = os.WriteFile(path, content, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
||||
func GetPython() (string, error) {
|
||||
|
||||
181
backend-golang/wsl.go
Normal file
@@ -0,0 +1,181 @@
|
||||
//go:build windows
|
||||
|
||||
package backend_golang
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"context"
|
||||
"errors"
|
||||
"io"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
su "github.com/nyaosorg/go-windows-su"
|
||||
wsl "github.com/ubuntu/gowsl"
|
||||
wruntime "github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
)
|
||||
|
||||
var distro *wsl.Distro
|
||||
var stdin io.WriteCloser
|
||||
var cmd *exec.Cmd
|
||||
|
||||
func isWslRunning() (bool, error) {
|
||||
if distro == nil {
|
||||
return false, nil
|
||||
}
|
||||
state, err := distro.State()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if state != wsl.Running {
|
||||
distro = nil
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (a *App) WslStart() error {
|
||||
running, err := isWslRunning()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if running {
|
||||
return nil
|
||||
}
|
||||
distros, err := wsl.RegisteredDistros(context.Background())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, d := range distros {
|
||||
if strings.Contains(d.Name(), "Ubuntu") {
|
||||
distro = &d
|
||||
break
|
||||
}
|
||||
}
|
||||
if distro == nil {
|
||||
return errors.New("ubuntu not found")
|
||||
}
|
||||
|
||||
cmd = exec.Command("wsl", "-d", distro.Name(), "-u", "root")
|
||||
|
||||
stdin, err = cmd.StdinPipe()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
stdout, err := cmd.StdoutPipe()
|
||||
cmd.Stderr = cmd.Stdout
|
||||
if err != nil {
|
||||
// stdin.Close()
|
||||
stdin = nil
|
||||
return err
|
||||
}
|
||||
|
||||
go func() {
|
||||
reader := bufio.NewReader(stdout)
|
||||
for {
|
||||
if stdin == nil {
|
||||
break
|
||||
}
|
||||
line, _, err := reader.ReadLine()
|
||||
if err != nil {
|
||||
wruntime.EventsEmit(a.ctx, "wslerr", err.Error())
|
||||
break
|
||||
}
|
||||
wruntime.EventsEmit(a.ctx, "wsl", string(line))
|
||||
}
|
||||
// stdout.Close()
|
||||
}()
|
||||
|
||||
if err := cmd.Start(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) WslCommand(command string) error {
|
||||
running, err := isWslRunning()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !running {
|
||||
return errors.New("wsl not running")
|
||||
}
|
||||
_, err = stdin.Write([]byte(command + "\n"))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) WslStop() error {
|
||||
running, err := isWslRunning()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !running {
|
||||
return errors.New("wsl not running")
|
||||
}
|
||||
if cmd != nil {
|
||||
err = cmd.Process.Kill()
|
||||
cmd = nil
|
||||
}
|
||||
// stdin.Close()
|
||||
stdin = nil
|
||||
distro = nil
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) WslIsEnabled() error {
|
||||
ex, err := os.Executable()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
exDir := filepath.Dir(ex)
|
||||
|
||||
data, err := os.ReadFile(exDir + "/wsl.state")
|
||||
if err == nil {
|
||||
if strings.Contains(string(data), "Enabled") {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
cmd := `-Command (Get-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux).State | Out-File -Encoding utf8 -FilePath ` + exDir + "/wsl.state"
|
||||
_, err = su.ShellExecute(su.RUNAS, "powershell", cmd, exDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
time.Sleep(2 * time.Second)
|
||||
data, err = os.ReadFile(exDir + "/wsl.state")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.Contains(string(data), "Enabled") {
|
||||
return nil
|
||||
} else {
|
||||
return errors.New("wsl is not enabled")
|
||||
}
|
||||
}
|
||||
|
||||
func (a *App) WslEnable(forceMode bool) error {
|
||||
cmd := `/online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux`
|
||||
_, err := su.ShellExecute(su.RUNAS, "dism", cmd, `C:\`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if forceMode {
|
||||
os.WriteFile("./wsl.state", []byte("Enabled"), 0644)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) WslInstallUbuntu() error {
|
||||
_, err := Cmd("ms-windows-store://pdp/?ProductId=9PN20MSR04DW")
|
||||
return err
|
||||
}
|
||||
31
backend-golang/wsl_not_windows.go
Normal file
@@ -0,0 +1,31 @@
|
||||
//go:build darwin || linux
|
||||
|
||||
package backend_golang
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
func (a *App) WslStart() error {
|
||||
return errors.New("wsl not supported")
|
||||
}
|
||||
|
||||
func (a *App) WslCommand(command string) error {
|
||||
return errors.New("wsl not supported")
|
||||
}
|
||||
|
||||
func (a *App) WslStop() error {
|
||||
return errors.New("wsl not supported")
|
||||
}
|
||||
|
||||
func (a *App) WslIsEnabled() error {
|
||||
return errors.New("wsl not supported")
|
||||
}
|
||||
|
||||
func (a *App) WslEnable(forceMode bool) error {
|
||||
return errors.New("wsl not supported")
|
||||
}
|
||||
|
||||
func (a *App) WslInstallUbuntu() error {
|
||||
return errors.New("wsl not supported")
|
||||
}
|
||||
22
backend-python/convert_model.py
vendored
@@ -219,13 +219,17 @@ def get_args():
|
||||
return p.parse_args()
|
||||
|
||||
|
||||
args = get_args()
|
||||
if not args.quiet:
|
||||
print(f"** {args}")
|
||||
try:
|
||||
args = get_args()
|
||||
if not args.quiet:
|
||||
print(f"** {args}")
|
||||
|
||||
RWKV(
|
||||
getattr(args, "in"),
|
||||
args.strategy,
|
||||
verbose=not args.quiet,
|
||||
convert_and_save_and_exit=args.out,
|
||||
)
|
||||
RWKV(
|
||||
getattr(args, "in"),
|
||||
args.strategy,
|
||||
verbose=not args.quiet,
|
||||
convert_and_save_and_exit=args.out,
|
||||
)
|
||||
except Exception as e:
|
||||
with open("error.txt", "w") as f:
|
||||
f.write(str(e))
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import lm_dataformat
|
||||
import ftfy
|
||||
import tqdm
|
||||
import tiktoken
|
||||
import GPUtil
|
||||
|
||||
import torch
|
||||
import rwkv
|
||||
import langchain
|
||||
import numpy
|
||||
import tokenizers
|
||||
import fastapi
|
||||
import uvicorn
|
||||
import sse_starlette
|
||||
|
||||
32321
backend-python/get-pip.py
vendored
Normal file
@@ -4,18 +4,18 @@ import sys
|
||||
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
import psutil
|
||||
from fastapi import FastAPI
|
||||
from fastapi import Depends, FastAPI
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
import uvicorn
|
||||
|
||||
from utils.rwkv import *
|
||||
from utils.torch import *
|
||||
from utils.ngrok import *
|
||||
from routes import completion, config
|
||||
from utils.log import log_middleware
|
||||
from routes import completion, config, state_cache
|
||||
import global_var
|
||||
|
||||
|
||||
app = FastAPI()
|
||||
app = FastAPI(dependencies=[Depends(log_middleware)])
|
||||
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
@@ -27,11 +27,13 @@ app.add_middleware(
|
||||
|
||||
app.include_router(completion.router)
|
||||
app.include_router(config.router)
|
||||
app.include_router(state_cache.router)
|
||||
|
||||
|
||||
@app.on_event("startup")
|
||||
def init():
|
||||
global_var.init()
|
||||
state_cache.init()
|
||||
|
||||
set_torch()
|
||||
|
||||
@@ -41,7 +43,7 @@ def init():
|
||||
|
||||
@app.get("/")
|
||||
def read_root():
|
||||
return {"Hello": "World!", "pid": os.getpid()}
|
||||
return {"Hello": "World!"}
|
||||
|
||||
|
||||
@app.post("/exit")
|
||||
@@ -59,7 +61,7 @@ def debug():
|
||||
strategy="cuda fp16",
|
||||
tokens_path="20B_tokenizer.json",
|
||||
)
|
||||
d = model.tokenizer.decode([])
|
||||
d = model.pipeline.decode([])
|
||||
print(d)
|
||||
|
||||
|
||||
|
||||
BIN
backend-python/requirements_without_cyac.txt
Normal file
@@ -2,19 +2,19 @@ import asyncio
|
||||
import json
|
||||
from threading import Lock
|
||||
from typing import List
|
||||
import base64
|
||||
|
||||
from fastapi import APIRouter, Request, status, HTTPException
|
||||
from sse_starlette.sse import EventSourceResponse
|
||||
from pydantic import BaseModel
|
||||
import numpy as np
|
||||
import tiktoken
|
||||
from utils.rwkv import *
|
||||
from utils.log import quick_log
|
||||
import global_var
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
interface = ":"
|
||||
user = "Bob"
|
||||
bot = "Alice"
|
||||
|
||||
|
||||
class Message(BaseModel):
|
||||
role: str
|
||||
@@ -27,9 +27,184 @@ class ChatCompletionBody(ModelConfigBody):
|
||||
stream: bool = False
|
||||
stop: str = None
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"messages": [{"role": "user", "content": "hello"}],
|
||||
"model": "rwkv",
|
||||
"stream": False,
|
||||
"stop": None,
|
||||
"max_tokens": 1000,
|
||||
"temperature": 1.2,
|
||||
"top_p": 0.5,
|
||||
"presence_penalty": 0.4,
|
||||
"frequency_penalty": 0.4,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class CompletionBody(ModelConfigBody):
|
||||
prompt: str
|
||||
model: str = "rwkv"
|
||||
stream: bool = False
|
||||
stop: str = None
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"prompt": "The following is an epic science fiction masterpiece that is immortalized, "
|
||||
+ "with delicate descriptions and grand depictions of interstellar civilization wars.\nChapter 1.\n",
|
||||
"model": "rwkv",
|
||||
"stream": False,
|
||||
"stop": None,
|
||||
"max_tokens": 100,
|
||||
"temperature": 1.2,
|
||||
"top_p": 0.5,
|
||||
"presence_penalty": 0.4,
|
||||
"frequency_penalty": 0.4,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
completion_lock = Lock()
|
||||
|
||||
requests_num = 0
|
||||
|
||||
|
||||
async def eval_rwkv(
|
||||
model: RWKV,
|
||||
request: Request,
|
||||
body: ModelConfigBody,
|
||||
prompt: str,
|
||||
stream: bool,
|
||||
stop: str,
|
||||
chat_mode: bool,
|
||||
):
|
||||
global requests_num
|
||||
requests_num = requests_num + 1
|
||||
quick_log(request, None, "Start Waiting. RequestsNum: " + str(requests_num))
|
||||
while completion_lock.locked():
|
||||
if await request.is_disconnected():
|
||||
requests_num = requests_num - 1
|
||||
print(f"{request.client} Stop Waiting (Lock)")
|
||||
quick_log(
|
||||
request,
|
||||
None,
|
||||
"Stop Waiting (Lock). RequestsNum: " + str(requests_num),
|
||||
)
|
||||
return
|
||||
await asyncio.sleep(0.1)
|
||||
else:
|
||||
with completion_lock:
|
||||
if await request.is_disconnected():
|
||||
requests_num = requests_num - 1
|
||||
print(f"{request.client} Stop Waiting (Lock)")
|
||||
quick_log(
|
||||
request,
|
||||
None,
|
||||
"Stop Waiting (Lock). RequestsNum: " + str(requests_num),
|
||||
)
|
||||
return
|
||||
set_rwkv_config(model, global_var.get(global_var.Model_Config))
|
||||
set_rwkv_config(model, body)
|
||||
|
||||
response, prompt_tokens, completion_tokens = "", 0, 0
|
||||
for response, delta, prompt_tokens, completion_tokens in model.generate(
|
||||
prompt,
|
||||
stop=stop,
|
||||
):
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
if stream:
|
||||
yield json.dumps(
|
||||
{
|
||||
"object": "chat.completion.chunk"
|
||||
if chat_mode
|
||||
else "text_completion",
|
||||
"response": response,
|
||||
"model": model.name,
|
||||
"choices": [
|
||||
{
|
||||
"delta": {"content": delta},
|
||||
"index": 0,
|
||||
"finish_reason": None,
|
||||
}
|
||||
if chat_mode
|
||||
else {
|
||||
"text": delta,
|
||||
"index": 0,
|
||||
"finish_reason": None,
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
# torch_gc()
|
||||
requests_num = requests_num - 1
|
||||
if await request.is_disconnected():
|
||||
print(f"{request.client} Stop Waiting")
|
||||
quick_log(
|
||||
request,
|
||||
body,
|
||||
response + "\nStop Waiting. RequestsNum: " + str(requests_num),
|
||||
)
|
||||
return
|
||||
quick_log(
|
||||
request,
|
||||
body,
|
||||
response + "\nFinished. RequestsNum: " + str(requests_num),
|
||||
)
|
||||
if stream:
|
||||
yield json.dumps(
|
||||
{
|
||||
"object": "chat.completion.chunk"
|
||||
if chat_mode
|
||||
else "text_completion",
|
||||
"response": response,
|
||||
"model": model.name,
|
||||
"choices": [
|
||||
{
|
||||
"delta": {},
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
if chat_mode
|
||||
else {
|
||||
"text": "",
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
yield "[DONE]"
|
||||
else:
|
||||
yield {
|
||||
"object": "chat.completion" if chat_mode else "text_completion",
|
||||
"response": response,
|
||||
"model": model.name,
|
||||
"usage": {
|
||||
"prompt_tokens": prompt_tokens,
|
||||
"completion_tokens": completion_tokens,
|
||||
"total_tokens": prompt_tokens + completion_tokens,
|
||||
},
|
||||
"choices": [
|
||||
{
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"content": response,
|
||||
},
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
if chat_mode
|
||||
else {
|
||||
"text": response,
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
@router.post("/v1/chat/completions")
|
||||
@router.post("/chat/completions")
|
||||
@@ -41,37 +216,56 @@ async def chat_completions(body: ChatCompletionBody, request: Request):
|
||||
question = body.messages[-1]
|
||||
if question.role == "user":
|
||||
question = question.content
|
||||
elif question.role == "system":
|
||||
question = body.messages[-2]
|
||||
if question.role == "user":
|
||||
question = question.content
|
||||
else:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "no question found")
|
||||
else:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "no question found")
|
||||
|
||||
completion_text = f"""
|
||||
interface = model.interface
|
||||
user = model.user
|
||||
bot = model.bot
|
||||
|
||||
completion_text = (
|
||||
f"""
|
||||
The following is a coherent verbose detailed conversation between a girl named {bot} and her friend {user}. \
|
||||
{bot} is very intelligent, creative and friendly. \
|
||||
{bot} is unlikely to disagree with {user}, and {bot} doesn't like to ask {user} questions. \
|
||||
{bot} likes to tell {user} a lot about herself and her opinions. \
|
||||
{bot} usually gives {user} kind, helpful and informative advices.\n
|
||||
"""
|
||||
if user == "Bob"
|
||||
else f"{user}{interface} hi\n\n{bot}{interface} Hi. "
|
||||
+ "I am your assistant and I will provide expert full response in full details. Please feel free to ask any question and I will always answer it.\n\n"
|
||||
)
|
||||
for message in body.messages:
|
||||
if message.role == "system":
|
||||
completion_text = (
|
||||
f"The following is a coherent verbose detailed conversation between a girl named {bot} and her friend {user}. "
|
||||
if user == "Bob"
|
||||
else f"{user}{interface} hi\n\n{bot}{interface} Hi. "
|
||||
+ message.content.replace("\\n", "\n")
|
||||
.replace("\r\n", "\n")
|
||||
.replace("\n\n", "\n")
|
||||
.replace("\n", " ")
|
||||
.strip()
|
||||
.replace("You are", f"{bot} is")
|
||||
.replace("you are", f"{bot} is")
|
||||
.replace("You're", f"{bot} is")
|
||||
.replace("you're", f"{bot} is")
|
||||
.replace("You", f"{bot}")
|
||||
.replace("you", f"{bot}")
|
||||
.replace("Your", f"{bot}'s")
|
||||
.replace("your", f"{bot}'s")
|
||||
.replace("你", f"{bot}")
|
||||
.replace("You are", f"{bot} is" if user == "Bob" else "I am")
|
||||
.replace("you are", f"{bot} is" if user == "Bob" else "I am")
|
||||
.replace("You're", f"{bot} is" if user == "Bob" else "I'm")
|
||||
.replace("you're", f"{bot} is" if user == "Bob" else "I'm")
|
||||
.replace("You", f"{bot}" if user == "Bob" else "I")
|
||||
.replace("you", f"{bot}" if user == "Bob" else "I")
|
||||
.replace("Your", f"{bot}'s" if user == "Bob" else "My")
|
||||
.replace("your", f"{bot}'s" if user == "Bob" else "my")
|
||||
.replace("你", f"{bot}" if user == "Bob" else "我")
|
||||
+ "\n\n"
|
||||
)
|
||||
elif message.role == "user":
|
||||
break
|
||||
for message in body.messages:
|
||||
if message.role == "user":
|
||||
completion_text += (
|
||||
f"{user}{interface} "
|
||||
+ message.content.replace("\\n", "\n")
|
||||
@@ -91,91 +285,18 @@ The following is a coherent verbose detailed conversation between a girl named {
|
||||
)
|
||||
completion_text += f"{bot}{interface}"
|
||||
|
||||
async def eval_rwkv():
|
||||
while completion_lock.locked():
|
||||
await asyncio.sleep(0.1)
|
||||
else:
|
||||
completion_lock.acquire()
|
||||
set_rwkv_config(model, global_var.get(global_var.Model_Config))
|
||||
set_rwkv_config(model, body)
|
||||
if body.stream:
|
||||
for response, delta in rwkv_generate(
|
||||
model,
|
||||
completion_text,
|
||||
stop=f"\n\n{user}" if body.stop is None else body.stop,
|
||||
):
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
yield json.dumps(
|
||||
{
|
||||
"response": response,
|
||||
"model": "rwkv",
|
||||
"choices": [
|
||||
{
|
||||
"delta": {"content": delta},
|
||||
"index": 0,
|
||||
"finish_reason": None,
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
# torch_gc()
|
||||
completion_lock.release()
|
||||
if await request.is_disconnected():
|
||||
return
|
||||
yield json.dumps(
|
||||
{
|
||||
"response": response,
|
||||
"model": "rwkv",
|
||||
"choices": [
|
||||
{
|
||||
"delta": {},
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
yield "[DONE]"
|
||||
else:
|
||||
response = None
|
||||
for response, delta in rwkv_generate(
|
||||
model,
|
||||
completion_text,
|
||||
stop=f"\n\n{user}" if body.stop is None else body.stop,
|
||||
):
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
# torch_gc()
|
||||
completion_lock.release()
|
||||
if await request.is_disconnected():
|
||||
return
|
||||
yield {
|
||||
"response": response,
|
||||
"model": "rwkv",
|
||||
"choices": [
|
||||
{
|
||||
"message": {
|
||||
"role": "assistant",
|
||||
"content": response,
|
||||
},
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
],
|
||||
}
|
||||
|
||||
stop = f"\n\n{user}" if body.stop is None else body.stop
|
||||
if body.stream:
|
||||
return EventSourceResponse(eval_rwkv())
|
||||
return EventSourceResponse(
|
||||
eval_rwkv(model, request, body, completion_text, body.stream, stop, True)
|
||||
)
|
||||
else:
|
||||
return await eval_rwkv().__anext__()
|
||||
|
||||
|
||||
class CompletionBody(ModelConfigBody):
|
||||
prompt: str
|
||||
model: str = "rwkv"
|
||||
stream: bool = False
|
||||
stop: str = None
|
||||
try:
|
||||
return await eval_rwkv(
|
||||
model, request, body, completion_text, body.stream, stop, True
|
||||
).__anext__()
|
||||
except StopAsyncIteration:
|
||||
return None
|
||||
|
||||
|
||||
@router.post("/v1/completions")
|
||||
@@ -185,74 +306,152 @@ async def completions(body: CompletionBody, request: Request):
|
||||
if model is None:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "model not loaded")
|
||||
|
||||
async def eval_rwkv():
|
||||
while completion_lock.locked():
|
||||
await asyncio.sleep(0.1)
|
||||
else:
|
||||
completion_lock.acquire()
|
||||
set_rwkv_config(model, global_var.get(global_var.Model_Config))
|
||||
set_rwkv_config(model, body)
|
||||
if body.stream:
|
||||
for response, delta in rwkv_generate(
|
||||
model, body.prompt, stop=body.stop
|
||||
):
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
yield json.dumps(
|
||||
{
|
||||
"response": response,
|
||||
"model": "rwkv",
|
||||
"choices": [
|
||||
{
|
||||
"text": delta,
|
||||
"index": 0,
|
||||
"finish_reason": None,
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
# torch_gc()
|
||||
completion_lock.release()
|
||||
if await request.is_disconnected():
|
||||
return
|
||||
yield json.dumps(
|
||||
{
|
||||
"response": response,
|
||||
"model": "rwkv",
|
||||
"choices": [
|
||||
{
|
||||
"text": "",
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
],
|
||||
}
|
||||
)
|
||||
yield "[DONE]"
|
||||
else:
|
||||
response = None
|
||||
for response, delta in rwkv_generate(
|
||||
model, body.prompt, stop=body.stop
|
||||
):
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
# torch_gc()
|
||||
completion_lock.release()
|
||||
if await request.is_disconnected():
|
||||
return
|
||||
yield {
|
||||
"response": response,
|
||||
"model": "rwkv",
|
||||
"choices": [
|
||||
{
|
||||
"text": response,
|
||||
"index": 0,
|
||||
"finish_reason": "stop",
|
||||
}
|
||||
],
|
||||
}
|
||||
if body.prompt is None or body.prompt == "":
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "prompt not found")
|
||||
|
||||
if body.stream:
|
||||
return EventSourceResponse(eval_rwkv())
|
||||
return EventSourceResponse(
|
||||
eval_rwkv(model, request, body, body.prompt, body.stream, body.stop, False)
|
||||
)
|
||||
else:
|
||||
return await eval_rwkv().__anext__()
|
||||
try:
|
||||
return await eval_rwkv(
|
||||
model, request, body, body.prompt, body.stream, body.stop, False
|
||||
).__anext__()
|
||||
except StopAsyncIteration:
|
||||
return None
|
||||
|
||||
|
||||
class EmbeddingsBody(BaseModel):
|
||||
input: str or List[str] or List[List[int]]
|
||||
model: str = "rwkv"
|
||||
encoding_format: str = None
|
||||
fast_mode: bool = False
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"input": "a big apple",
|
||||
"model": "rwkv",
|
||||
"encoding_format": None,
|
||||
"fast_mode": False,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def embedding_base64(embedding: List[float]) -> str:
|
||||
return base64.b64encode(np.array(embedding).astype(np.float32)).decode("utf-8")
|
||||
|
||||
|
||||
@router.post("/v1/embeddings")
|
||||
@router.post("/embeddings")
|
||||
@router.post("/v1/engines/text-embedding-ada-002/embeddings")
|
||||
@router.post("/engines/text-embedding-ada-002/embeddings")
|
||||
async def embeddings(body: EmbeddingsBody, request: Request):
|
||||
model: RWKV = global_var.get(global_var.Model)
|
||||
if model is None:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "model not loaded")
|
||||
|
||||
if body.input is None or body.input == "" or body.input == [] or body.input == [[]]:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "input not found")
|
||||
|
||||
global requests_num
|
||||
requests_num = requests_num + 1
|
||||
quick_log(request, None, "Start Waiting. RequestsNum: " + str(requests_num))
|
||||
while completion_lock.locked():
|
||||
if await request.is_disconnected():
|
||||
requests_num = requests_num - 1
|
||||
print(f"{request.client} Stop Waiting (Lock)")
|
||||
quick_log(
|
||||
request,
|
||||
None,
|
||||
"Stop Waiting (Lock). RequestsNum: " + str(requests_num),
|
||||
)
|
||||
return
|
||||
await asyncio.sleep(0.1)
|
||||
else:
|
||||
with completion_lock:
|
||||
if await request.is_disconnected():
|
||||
requests_num = requests_num - 1
|
||||
print(f"{request.client} Stop Waiting (Lock)")
|
||||
quick_log(
|
||||
request,
|
||||
None,
|
||||
"Stop Waiting (Lock). RequestsNum: " + str(requests_num),
|
||||
)
|
||||
return
|
||||
|
||||
base64_format = False
|
||||
if body.encoding_format == "base64":
|
||||
base64_format = True
|
||||
|
||||
embeddings = []
|
||||
prompt_tokens = 0
|
||||
if type(body.input) == list:
|
||||
if type(body.input[0]) == list:
|
||||
encoding = tiktoken.model.encoding_for_model(
|
||||
"text-embedding-ada-002"
|
||||
)
|
||||
for i in range(len(body.input)):
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
input = encoding.decode(body.input[i])
|
||||
embedding, token_len = model.get_embedding(
|
||||
input, body.fast_mode
|
||||
)
|
||||
prompt_tokens = prompt_tokens + token_len
|
||||
if base64_format:
|
||||
embedding = embedding_base64(embedding)
|
||||
embeddings.append(embedding)
|
||||
else:
|
||||
for i in range(len(body.input)):
|
||||
if await request.is_disconnected():
|
||||
break
|
||||
embedding, token_len = model.get_embedding(
|
||||
body.input[i], body.fast_mode
|
||||
)
|
||||
prompt_tokens = prompt_tokens + token_len
|
||||
if base64_format:
|
||||
embedding = embedding_base64(embedding)
|
||||
embeddings.append(embedding)
|
||||
else:
|
||||
embedding, prompt_tokens = model.get_embedding(
|
||||
body.input, body.fast_mode
|
||||
)
|
||||
if base64_format:
|
||||
embedding = embedding_base64(embedding)
|
||||
embeddings.append(embedding)
|
||||
|
||||
requests_num = requests_num - 1
|
||||
if await request.is_disconnected():
|
||||
print(f"{request.client} Stop Waiting")
|
||||
quick_log(
|
||||
request,
|
||||
None,
|
||||
"Stop Waiting. RequestsNum: " + str(requests_num),
|
||||
)
|
||||
return
|
||||
quick_log(
|
||||
request,
|
||||
None,
|
||||
"Finished. RequestsNum: " + str(requests_num),
|
||||
)
|
||||
|
||||
ret_data = [
|
||||
{
|
||||
"object": "embedding",
|
||||
"index": i,
|
||||
"embedding": embedding,
|
||||
}
|
||||
for i, embedding in enumerate(embeddings)
|
||||
]
|
||||
|
||||
return {
|
||||
"object": "list",
|
||||
"data": ret_data,
|
||||
"model": model.name,
|
||||
"usage": {
|
||||
"prompt_tokens": prompt_tokens,
|
||||
"total_tokens": prompt_tokens,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import pathlib
|
||||
from utils.log import quick_log
|
||||
|
||||
from fastapi import APIRouter, HTTPException, Response, status
|
||||
from fastapi import APIRouter, HTTPException, Request, Response, status as Status
|
||||
from pydantic import BaseModel
|
||||
from langchain.llms import RWKV
|
||||
from utils.rwkv import *
|
||||
from utils.torch import *
|
||||
import global_var
|
||||
@@ -11,22 +11,47 @@ import GPUtil
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
def get_tokens_path(model_path: str):
|
||||
model_path = model_path.lower()
|
||||
default_tokens_path = (
|
||||
f"{pathlib.Path(__file__).parent.parent.resolve()}/rwkv_pip/20B_tokenizer.json"
|
||||
)
|
||||
if "raven" in model_path:
|
||||
return default_tokens_path
|
||||
elif "world" in model_path:
|
||||
return "rwkv_vocab_v20230424"
|
||||
else:
|
||||
return default_tokens_path
|
||||
|
||||
|
||||
class SwitchModelBody(BaseModel):
|
||||
model: str
|
||||
strategy: str
|
||||
customCuda: bool = False
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"model": "models/RWKV-4-World-3B-v1-20230619-ctx4096.pth",
|
||||
"strategy": "cuda fp16",
|
||||
"customCuda": False,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@router.post("/switch-model")
|
||||
def switch_model(body: SwitchModelBody, response: Response):
|
||||
def switch_model(body: SwitchModelBody, response: Response, request: Request):
|
||||
if global_var.get(global_var.Model_Status) is global_var.ModelStatus.Loading:
|
||||
response.status_code = status.HTTP_304_NOT_MODIFIED
|
||||
response.status_code = Status.HTTP_304_NOT_MODIFIED
|
||||
return
|
||||
|
||||
global_var.set(global_var.Model_Status, global_var.ModelStatus.Offline)
|
||||
global_var.set(global_var.Model, None)
|
||||
torch_gc()
|
||||
|
||||
if body.model == "":
|
||||
return "success"
|
||||
|
||||
os.environ["RWKV_CUDA_ON"] = "1" if body.customCuda else "0"
|
||||
|
||||
global_var.set(global_var.Model_Status, global_var.ModelStatus.Loading)
|
||||
@@ -36,13 +61,16 @@ def switch_model(body: SwitchModelBody, response: Response):
|
||||
RWKV(
|
||||
model=body.model,
|
||||
strategy=body.strategy,
|
||||
tokens_path=f"{pathlib.Path(__file__).parent.parent.resolve()}/20B_tokenizer.json",
|
||||
tokens_path=get_tokens_path(body.model),
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
print(e)
|
||||
quick_log(request, body, f"Exception: {e}")
|
||||
global_var.set(global_var.Model_Status, global_var.ModelStatus.Offline)
|
||||
raise HTTPException(status.HTTP_500_INTERNAL_SERVER_ERROR, "failed to load")
|
||||
raise HTTPException(
|
||||
Status.HTTP_500_INTERNAL_SERVER_ERROR, f"failed to load: {e}"
|
||||
)
|
||||
|
||||
if global_var.get(global_var.Model_Config) is None:
|
||||
global_var.set(
|
||||
|
||||
161
backend-python/routes/state_cache.py
Normal file
@@ -0,0 +1,161 @@
|
||||
from typing import Any, Dict, List
|
||||
from utils.log import quick_log
|
||||
from fastapi import APIRouter, HTTPException, Request, Response, status
|
||||
from pydantic import BaseModel
|
||||
import gc
|
||||
import copy
|
||||
import sys
|
||||
import torch
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
trie = None
|
||||
dtrie: Dict = {}
|
||||
max_trie_len = 3000
|
||||
loop_start_id = 1 # to prevent preloaded prompts from being deleted
|
||||
loop_del_trie_id = loop_start_id
|
||||
|
||||
|
||||
def init():
|
||||
global trie
|
||||
try:
|
||||
import cyac
|
||||
|
||||
# import mmap
|
||||
# import os
|
||||
#
|
||||
# if os.path.exists("state_cache.trie"):
|
||||
# with open("state_cache.trie", "r") as bf:
|
||||
# buff_object = mmap.mmap(bf.fileno(), 0, access=mmap.ACCESS_READ)
|
||||
# trie = cyac.Trie.from_buff(buff_object, copy=False)
|
||||
# else:
|
||||
trie = cyac.Trie()
|
||||
except ModuleNotFoundError:
|
||||
print("cyac not found")
|
||||
|
||||
|
||||
class AddStateBody(BaseModel):
|
||||
prompt: str
|
||||
tokens: List[str]
|
||||
state: Any
|
||||
logits: Any
|
||||
|
||||
|
||||
@router.post("/add-state")
|
||||
def add_state(body: AddStateBody):
|
||||
global trie, dtrie, loop_del_trie_id
|
||||
if trie is None:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "trie not loaded")
|
||||
|
||||
try:
|
||||
id: int = trie.insert(body.prompt)
|
||||
device: torch.device = body.state[0].device
|
||||
dtrie[id] = {
|
||||
"tokens": copy.deepcopy(body.tokens),
|
||||
"state": [tensor.cpu() for tensor in body.state]
|
||||
if device != torch.device("cpu")
|
||||
else copy.deepcopy(body.state),
|
||||
"logits": copy.deepcopy(body.logits),
|
||||
"device": device,
|
||||
}
|
||||
|
||||
if len(trie) >= max_trie_len:
|
||||
del_prompt = trie[loop_del_trie_id]
|
||||
trie.remove(del_prompt)
|
||||
dtrie[loop_del_trie_id] = None
|
||||
loop_del_trie_id = loop_del_trie_id + 1
|
||||
if loop_del_trie_id >= max_trie_len:
|
||||
loop_del_trie_id = loop_start_id
|
||||
|
||||
quick_log(
|
||||
None,
|
||||
None,
|
||||
f"New Trie Id: {id}\nTrie Len: {len(trie)}\nTrie Buff Size: {trie.buff_size()}\nDtrie Buff Size Of Id: {_get_a_dtrie_buff_size(dtrie[id])}",
|
||||
)
|
||||
return "success"
|
||||
except Exception as e:
|
||||
raise HTTPException(
|
||||
status.HTTP_400_BAD_REQUEST, f"insert failed, bad prompt.\n{e}"
|
||||
)
|
||||
|
||||
|
||||
@router.post("/reset-state")
|
||||
def reset_state():
|
||||
global trie, dtrie
|
||||
if trie is None:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "trie not loaded")
|
||||
|
||||
trie = cyac.Trie()
|
||||
dtrie = {}
|
||||
gc.collect()
|
||||
|
||||
return "success"
|
||||
|
||||
|
||||
class LongestPrefixStateBody(BaseModel):
|
||||
prompt: str
|
||||
|
||||
|
||||
def _get_a_dtrie_buff_size(dtrie_v):
|
||||
# print(sys.getsizeof(dtrie_v["tokens"][0])) # str
|
||||
# print(sys.getsizeof(dtrie_v["tokens"][0]) * len(dtrie_v["tokens"]))
|
||||
# print(dtrie_v["state"][0][0].element_size())
|
||||
# print(dtrie_v["state"][0].nelement())
|
||||
# print(len(dtrie_v["state"]))
|
||||
# print(
|
||||
# len(dtrie_v["state"])
|
||||
# * dtrie_v["state"][0].nelement()
|
||||
# * dtrie_v["state"][0][0].element_size()
|
||||
# )
|
||||
# print(dtrie_v["logits"][0].element_size())
|
||||
# print(dtrie_v["logits"].nelement())
|
||||
# print(dtrie_v["logits"][0].element_size() * dtrie_v["logits"].nelement())
|
||||
return 54 * len(dtrie_v["tokens"]) + 491520 + 262144 + 28 # TODO
|
||||
|
||||
|
||||
@router.post("/longest-prefix-state")
|
||||
def longest_prefix_state(body: LongestPrefixStateBody, request: Request):
|
||||
global trie
|
||||
if trie is None:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "trie not loaded")
|
||||
|
||||
id = -1
|
||||
try:
|
||||
for id, len in trie.prefix(body.prompt):
|
||||
pass
|
||||
except:
|
||||
pass
|
||||
if id != -1:
|
||||
v = dtrie[id]
|
||||
device: torch.device = v["device"]
|
||||
prompt: str = trie[id]
|
||||
|
||||
quick_log(request, body, "Hit:\n" + prompt)
|
||||
return {
|
||||
"prompt": prompt,
|
||||
"tokens": v["tokens"],
|
||||
"state": [tensor.to(device) for tensor in v["state"]]
|
||||
if device != torch.device("cpu")
|
||||
else v["state"],
|
||||
"logits": v["logits"],
|
||||
"device": device.type,
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"prompt": "",
|
||||
"tokens": [],
|
||||
"state": None,
|
||||
"logits": None,
|
||||
"device": None,
|
||||
}
|
||||
|
||||
|
||||
@router.post("/save-state")
|
||||
def save_state():
|
||||
global trie
|
||||
if trie is None:
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST, "trie not loaded")
|
||||
|
||||
# trie.save("state_cache.trie")
|
||||
|
||||
return "not implemented"
|
||||
106
backend-python/rwkv_pip/rwkv_tokenizer.py
vendored
Normal file
@@ -0,0 +1,106 @@
|
||||
########################################################################################################
|
||||
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
|
||||
########################################################################################################
|
||||
|
||||
|
||||
class TRIE:
|
||||
__slots__ = tuple("ch,to,values,front".split(","))
|
||||
to: list
|
||||
values: set
|
||||
|
||||
def __init__(self, front=None, ch=None):
|
||||
self.ch = ch
|
||||
self.to = [None for ch in range(256)]
|
||||
self.values = set()
|
||||
self.front = front
|
||||
|
||||
def __repr__(self):
|
||||
fr = self
|
||||
ret = []
|
||||
while fr != None:
|
||||
if fr.ch != None:
|
||||
ret.append(fr.ch)
|
||||
fr = fr.front
|
||||
return "<TRIE %s %s>" % (ret[::-1], self.values)
|
||||
|
||||
def add(self, key: bytes, idx: int = 0, val=None):
|
||||
if idx == len(key):
|
||||
if val is None:
|
||||
val = key
|
||||
self.values.add(val)
|
||||
return self
|
||||
ch = key[idx]
|
||||
if self.to[ch] is None:
|
||||
self.to[ch] = TRIE(front=self, ch=ch)
|
||||
return self.to[ch].add(key, idx=idx + 1, val=val)
|
||||
|
||||
def find_longest(self, key: bytes, idx: int = 0):
|
||||
u: TRIE = self
|
||||
ch: int = key[idx]
|
||||
|
||||
while u.to[ch] is not None:
|
||||
u = u.to[ch]
|
||||
idx += 1
|
||||
if u.values:
|
||||
ret = idx, u, u.values
|
||||
if idx == len(key):
|
||||
break
|
||||
ch = key[idx]
|
||||
return ret
|
||||
|
||||
|
||||
class TRIE_TOKENIZER:
|
||||
def __init__(self, file_name):
|
||||
self.idx2token = {}
|
||||
sorted = [] # must be already sorted
|
||||
with open(file_name, "r", encoding="utf-8") as f:
|
||||
lines = f.readlines()
|
||||
for l in lines:
|
||||
idx = int(l[: l.index(" ")])
|
||||
x = eval(l[l.index(" ") : l.rindex(" ")])
|
||||
x = x.encode("utf-8") if isinstance(x, str) else x
|
||||
assert isinstance(x, bytes)
|
||||
assert len(x) == int(l[l.rindex(" ") :])
|
||||
sorted += [x]
|
||||
self.idx2token[idx] = x
|
||||
|
||||
self.token2idx = {}
|
||||
for k, v in self.idx2token.items():
|
||||
self.token2idx[v] = int(k)
|
||||
|
||||
self.root = TRIE()
|
||||
for t, i in self.token2idx.items():
|
||||
_ = self.root.add(t, val=(t, i))
|
||||
|
||||
def encodeBytes(self, src: bytes):
|
||||
idx: int = 0
|
||||
tokens = []
|
||||
while idx < len(src):
|
||||
_idx: int = idx
|
||||
idx, _, values = self.root.find_longest(src, idx)
|
||||
assert idx != _idx
|
||||
_, token = next(iter(values))
|
||||
tokens.append(token)
|
||||
return tokens
|
||||
|
||||
def decodeBytes(self, tokens):
|
||||
return b"".join(map(lambda i: self.idx2token[i], tokens))
|
||||
|
||||
def encode(self, src):
|
||||
return self.encodeBytes(src.encode("utf-8"))
|
||||
|
||||
def decode(self, tokens):
|
||||
try:
|
||||
return self.decodeBytes(tokens).decode("utf-8")
|
||||
except:
|
||||
return "\ufffd" # bad utf-8
|
||||
|
||||
def printTokens(self, tokens):
|
||||
for i in tokens:
|
||||
s = self.idx2token[i]
|
||||
try:
|
||||
s = s.decode("utf-8")
|
||||
except:
|
||||
pass
|
||||
print(f"{repr(s)}{i}", end=" ")
|
||||
print()
|
||||
65529
backend-python/rwkv_pip/rwkv_vocab_v20230424.txt
vendored
Normal file
142
backend-python/rwkv_pip/utils.py
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
########################################################################################################
|
||||
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
|
||||
########################################################################################################
|
||||
|
||||
import os, sys
|
||||
import numpy as np
|
||||
import torch
|
||||
from torch.nn import functional as F
|
||||
|
||||
|
||||
class PIPELINE_ARGS:
|
||||
def __init__(
|
||||
self,
|
||||
temperature=1.0,
|
||||
top_p=0.85,
|
||||
top_k=0,
|
||||
alpha_frequency=0.2,
|
||||
alpha_presence=0.2,
|
||||
token_ban=[],
|
||||
token_stop=[],
|
||||
chunk_len=256,
|
||||
):
|
||||
self.temperature = temperature
|
||||
self.top_p = top_p
|
||||
self.top_k = top_k
|
||||
self.alpha_frequency = alpha_frequency # Frequency Penalty (as in GPT-3)
|
||||
self.alpha_presence = alpha_presence # Presence Penalty (as in GPT-3)
|
||||
self.token_ban = token_ban # ban the generation of some tokens
|
||||
self.token_stop = token_stop # stop generation whenever you see any token here
|
||||
self.chunk_len = (
|
||||
chunk_len # split input into chunks to save VRAM (shorter -> slower)
|
||||
)
|
||||
|
||||
|
||||
class PIPELINE:
|
||||
def __init__(self, model, WORD_NAME):
|
||||
self.model = model
|
||||
if WORD_NAME == "cl100k_base":
|
||||
import tiktoken
|
||||
|
||||
self.tokenizer = tiktoken.get_encoding(WORD_NAME)
|
||||
elif WORD_NAME == "rwkv_vocab_v20230424":
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
from rwkv_tokenizer import TRIE_TOKENIZER
|
||||
|
||||
self.tokenizer = TRIE_TOKENIZER(
|
||||
os.path.dirname(os.path.abspath(__file__)) + "/rwkv_vocab_v20230424.txt"
|
||||
)
|
||||
else:
|
||||
from tokenizers import Tokenizer
|
||||
|
||||
self.tokenizer = Tokenizer.from_file(WORD_NAME)
|
||||
|
||||
def refine_context(self, context):
|
||||
context = context.strip().split("\n")
|
||||
for c in range(len(context)):
|
||||
context[c] = context[c].strip().strip("\u3000").strip("\r")
|
||||
context = list(filter(lambda c: c != "", context))
|
||||
context = "\n" + ("\n".join(context)).strip()
|
||||
if context == "":
|
||||
context = "\n"
|
||||
return context
|
||||
|
||||
def encode(self, x):
|
||||
if "Tokenizer" in str(type(self.tokenizer)):
|
||||
return self.tokenizer.encode(x).ids
|
||||
else:
|
||||
return self.tokenizer.encode(x)
|
||||
|
||||
def decode(self, x):
|
||||
return self.tokenizer.decode(x)
|
||||
|
||||
def sample_logits(self, logits, temperature=1.0, top_p=0.85, top_k=0):
|
||||
probs = F.softmax(logits.float(), dim=-1)
|
||||
top_k = int(top_k)
|
||||
if probs.device == torch.device("cpu"):
|
||||
probs = probs.numpy()
|
||||
sorted_ids = np.argsort(probs)
|
||||
sorted_probs = probs[sorted_ids][::-1]
|
||||
cumulative_probs = np.cumsum(sorted_probs)
|
||||
cutoff = float(sorted_probs[np.argmax(cumulative_probs > top_p)])
|
||||
probs[probs < cutoff] = 0
|
||||
if top_k < len(probs) and top_k > 0:
|
||||
probs[sorted_ids[:-top_k]] = 0
|
||||
if temperature != 1.0:
|
||||
probs = probs ** (1.0 / temperature)
|
||||
probs = probs / np.sum(probs)
|
||||
out = np.random.choice(a=len(probs), p=probs)
|
||||
return int(out)
|
||||
else:
|
||||
sorted_ids = torch.argsort(probs)
|
||||
sorted_probs = probs[sorted_ids]
|
||||
sorted_probs = torch.flip(sorted_probs, dims=(0,))
|
||||
cumulative_probs = torch.cumsum(sorted_probs, dim=-1).cpu().numpy()
|
||||
cutoff = float(sorted_probs[np.argmax(cumulative_probs > top_p)])
|
||||
probs[probs < cutoff] = 0
|
||||
if top_k < len(probs) and top_k > 0:
|
||||
probs[sorted_ids[:-top_k]] = 0
|
||||
if temperature != 1.0:
|
||||
probs = probs ** (1.0 / temperature)
|
||||
out = torch.multinomial(probs, num_samples=1)[0]
|
||||
return int(out)
|
||||
|
||||
def generate(
|
||||
self, ctx, token_count=100, args=PIPELINE_ARGS(), callback=None, state=None
|
||||
):
|
||||
all_tokens = []
|
||||
out_last = 0
|
||||
out_str = ""
|
||||
occurrence = {}
|
||||
for i in range(token_count):
|
||||
# forward & adjust prob.
|
||||
tokens = self.encode(ctx) if i == 0 else [token]
|
||||
while len(tokens) > 0:
|
||||
out, state = self.model.forward(tokens[: args.chunk_len], state)
|
||||
tokens = tokens[args.chunk_len :]
|
||||
|
||||
for n in args.token_ban:
|
||||
out[n] = -float("inf")
|
||||
for n in occurrence:
|
||||
out[n] -= args.alpha_presence + occurrence[n] * args.alpha_frequency
|
||||
|
||||
# sampler
|
||||
token = self.sample_logits(
|
||||
out, temperature=args.temperature, top_p=args.top_p, top_k=args.top_k
|
||||
)
|
||||
if token in args.token_stop:
|
||||
break
|
||||
all_tokens += [token]
|
||||
if token not in occurrence:
|
||||
occurrence[token] = 1
|
||||
else:
|
||||
occurrence[token] += 1
|
||||
|
||||
# output
|
||||
tmp = self.decode(all_tokens[out_last:])
|
||||
if "\ufffd" not in tmp: # is valid utf-8 string?
|
||||
if callback:
|
||||
callback(tmp)
|
||||
out_str += tmp
|
||||
out_last = i + 1
|
||||
return out_str
|
||||
38
backend-python/utils/log.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import json
|
||||
import logging
|
||||
from typing import Any
|
||||
from fastapi import Request
|
||||
|
||||
|
||||
logger = logging.getLogger()
|
||||
logger.setLevel(logging.INFO)
|
||||
formatter = logging.Formatter("%(asctime)s - %(levelname)s\n%(message)s")
|
||||
fh = logging.handlers.RotatingFileHandler(
|
||||
"api.log", mode="a", maxBytes=3 * 1024 * 1024, backupCount=3
|
||||
)
|
||||
fh.setFormatter(formatter)
|
||||
logger.addHandler(fh)
|
||||
|
||||
|
||||
def quick_log(request: Request, body: Any, response: str):
|
||||
try:
|
||||
logger.info(
|
||||
f"Client: {request.client if request else ''}\nUrl: {request.url if request else ''}\n"
|
||||
+ (
|
||||
f"Body: {json.dumps(body.__dict__, default=vars, ensure_ascii=False)}\n"
|
||||
if body
|
||||
else ""
|
||||
)
|
||||
+ (f"Data:\n{response}\n" if response else "")
|
||||
)
|
||||
except Exception as e:
|
||||
logger.info(f"Error quick_log request:\n{e}")
|
||||
|
||||
|
||||
async def log_middleware(request: Request):
|
||||
try:
|
||||
logger.info(
|
||||
f"Client: {request.client}\nUrl: {request.url}\nBody: {await request.body()}\n"
|
||||
)
|
||||
except Exception as e:
|
||||
logger.info(f"Error log_middleware request:\n{e}")
|
||||
@@ -1,28 +1,397 @@
|
||||
import os
|
||||
import pathlib
|
||||
from typing import Dict
|
||||
from langchain.llms import RWKV
|
||||
from pydantic import BaseModel
|
||||
import copy
|
||||
from typing import Dict, List, Tuple
|
||||
from utils.log import quick_log
|
||||
from fastapi import HTTPException
|
||||
from pydantic import BaseModel, Field
|
||||
import torch
|
||||
import numpy as np
|
||||
from rwkv_pip.utils import PIPELINE
|
||||
from routes import state_cache
|
||||
|
||||
|
||||
END_OF_TEXT = 0
|
||||
END_OF_LINE_DOUBLE = 535
|
||||
|
||||
|
||||
os.environ["TORCH_EXTENSIONS_DIR"] = f"{pathlib.Path(__file__).parent.parent.resolve()}"
|
||||
|
||||
|
||||
class RWKV:
|
||||
def __init__(self, model: str, strategy: str, tokens_path: str) -> None:
|
||||
from rwkv.model import RWKV as Model # dynamic import to make RWKV_CUDA_ON work
|
||||
|
||||
filename, _ = os.path.splitext(os.path.basename(model))
|
||||
self.name = filename
|
||||
self.model = Model(model, strategy)
|
||||
self.pipeline = PIPELINE(self.model, tokens_path)
|
||||
self.model_state = None
|
||||
self.model_tokens = []
|
||||
|
||||
self.CHUNK_LEN = 256
|
||||
|
||||
self.max_tokens_per_generation = 500
|
||||
self.temperature = 1
|
||||
self.top_p = 0.5
|
||||
self.penalty_alpha_presence = 0.4
|
||||
self.penalty_alpha_frequency = 0.4
|
||||
|
||||
self.interface = ":"
|
||||
if "world" in self.name.lower():
|
||||
self.user = "Question"
|
||||
self.bot = "Answer"
|
||||
self.END_OF_LINE = 11
|
||||
else:
|
||||
self.user = "Bob"
|
||||
self.bot = "Alice"
|
||||
self.END_OF_LINE = 187
|
||||
|
||||
self.AVOID_REPEAT_TOKENS = []
|
||||
AVOID_REPEAT = ",:?!"
|
||||
for i in AVOID_REPEAT:
|
||||
dd = self.pipeline.encode(i)
|
||||
assert len(dd) == 1
|
||||
self.AVOID_REPEAT_TOKENS += dd
|
||||
|
||||
self.preload()
|
||||
|
||||
def preload(self):
|
||||
interface = self.interface
|
||||
user = self.user
|
||||
bot = self.bot
|
||||
preset_system = (
|
||||
f"""
|
||||
The following is a coherent verbose detailed conversation between a girl named {bot} and her friend {user}. \
|
||||
{bot} is very intelligent, creative and friendly. \
|
||||
{bot} is unlikely to disagree with {user}, and {bot} doesn't like to ask {user} questions. \
|
||||
{bot} likes to tell {user} a lot about herself and her opinions. \
|
||||
{bot} usually gives {user} kind, helpful and informative advices.\n
|
||||
"""
|
||||
if self.user == "Bob"
|
||||
else f"{user}{interface} hi\n\n{bot}{interface} Hi. "
|
||||
+ "I am your assistant and I will provide expert full response in full details. Please feel free to ask any question and I will always answer it.\n\n"
|
||||
)
|
||||
logits, _ = self.run_rnn(self.fix_tokens(self.pipeline.encode(preset_system)))
|
||||
try:
|
||||
state_cache.add_state(
|
||||
state_cache.AddStateBody(
|
||||
prompt=preset_system,
|
||||
tokens=self.model_tokens,
|
||||
state=self.model_state,
|
||||
logits=logits,
|
||||
)
|
||||
)
|
||||
except HTTPException:
|
||||
pass
|
||||
|
||||
# Model only saw '\n\n' as [187, 187] before, but the tokenizer outputs [535] for it at the end
|
||||
def fix_tokens(self, tokens):
|
||||
if "world" in self.name.lower():
|
||||
return tokens
|
||||
if len(tokens) > 0 and tokens[-1] == END_OF_LINE_DOUBLE:
|
||||
tokens = tokens[:-1] + [self.END_OF_LINE, self.END_OF_LINE]
|
||||
return tokens
|
||||
|
||||
def run_rnn(self, _tokens: List[str], newline_adj: int = 0):
|
||||
tokens = [int(x) for x in _tokens]
|
||||
token_len = len(tokens)
|
||||
self.model_tokens += tokens
|
||||
|
||||
while len(tokens) > 0:
|
||||
out, self.model_state = self.model.forward(
|
||||
tokens[: self.CHUNK_LEN], self.model_state
|
||||
)
|
||||
tokens = tokens[self.CHUNK_LEN :]
|
||||
|
||||
out[self.END_OF_LINE] += newline_adj # adjust \n probability
|
||||
|
||||
if self.model_tokens[-1] in self.AVOID_REPEAT_TOKENS:
|
||||
out[self.model_tokens[-1]] = -999999999
|
||||
return out, token_len
|
||||
|
||||
def get_embedding(self, input: str, fast_mode: bool) -> Tuple[List[float], int]:
|
||||
if fast_mode:
|
||||
embedding, token_len = self.fast_embedding(
|
||||
self.fix_tokens(self.pipeline.encode(input)), None
|
||||
)
|
||||
else:
|
||||
self.model_state = None
|
||||
self.model_tokens = []
|
||||
_, token_len = self.run_rnn(self.fix_tokens(self.pipeline.encode(input)))
|
||||
embedding = self.model_state[-5].tolist()
|
||||
embedding = (embedding / np.linalg.norm(embedding)).tolist()
|
||||
return embedding, token_len
|
||||
|
||||
def fast_embedding(self, tokens: List[str], state):
|
||||
tokens = [int(x) for x in tokens]
|
||||
token_len = len(tokens)
|
||||
self = self.model
|
||||
|
||||
with torch.no_grad():
|
||||
w = self.w
|
||||
args = self.args
|
||||
|
||||
if state == None:
|
||||
state = [None] * args.n_layer * 5
|
||||
for i in range(
|
||||
args.n_layer
|
||||
): # state: 0=att_xx 1=att_aa 2=att_bb 3=att_pp 4=ffn_xx
|
||||
dd = self.strategy[i]
|
||||
dev = dd.device
|
||||
atype = dd.atype
|
||||
state[i * 5 + 0] = torch.zeros(
|
||||
args.n_embd, dtype=atype, requires_grad=False, device=dev
|
||||
).contiguous()
|
||||
state[i * 5 + 1] = torch.zeros(
|
||||
args.n_embd, dtype=torch.float, requires_grad=False, device=dev
|
||||
).contiguous()
|
||||
state[i * 5 + 2] = torch.zeros(
|
||||
args.n_embd, dtype=torch.float, requires_grad=False, device=dev
|
||||
).contiguous()
|
||||
state[i * 5 + 3] = (
|
||||
torch.zeros(
|
||||
args.n_embd,
|
||||
dtype=torch.float,
|
||||
requires_grad=False,
|
||||
device=dev,
|
||||
).contiguous()
|
||||
- 1e30
|
||||
)
|
||||
state[i * 5 + 4] = torch.zeros(
|
||||
args.n_embd, dtype=atype, requires_grad=False, device=dev
|
||||
).contiguous()
|
||||
|
||||
break
|
||||
|
||||
seq_mode = len(tokens) > 1
|
||||
|
||||
x = w["emb.weight"][tokens if seq_mode else tokens[0]]
|
||||
|
||||
for i in range(args.n_layer):
|
||||
bbb = f"blocks.{i}."
|
||||
att = f"blocks.{i}.att."
|
||||
ffn = f"blocks.{i}.ffn."
|
||||
dd = self.strategy[i]
|
||||
dev = dd.device
|
||||
atype = dd.atype
|
||||
wtype = dd.wtype
|
||||
if seq_mode:
|
||||
if "cuda" in str(dev) and os.environ["RWKV_CUDA_ON"] == "1":
|
||||
ATT = (
|
||||
self.cuda_att_seq
|
||||
if wtype != torch.uint8
|
||||
else self.cuda_att_seq_i8
|
||||
)
|
||||
else:
|
||||
ATT = self.att_seq if wtype != torch.uint8 else self.att_seq_i8
|
||||
FFN = self.ffn_seq if wtype != torch.uint8 else self.ffn_seq_i8
|
||||
else:
|
||||
ATT = self.att_one if wtype != torch.uint8 else self.att_one_i8
|
||||
FFN = self.ffn_one if wtype != torch.uint8 else self.ffn_one_i8
|
||||
|
||||
x = x.to(dtype=atype, device=dev)
|
||||
|
||||
kw = w[f"{att}key.weight"]
|
||||
vw = w[f"{att}value.weight"]
|
||||
rw = w[f"{att}receptance.weight"]
|
||||
ow = w[f"{att}output.weight"]
|
||||
if dd.stream:
|
||||
kw = kw.to(device=dev, non_blocking=True)
|
||||
vw = vw.to(device=dev, non_blocking=True)
|
||||
rw = rw.to(device=dev, non_blocking=True)
|
||||
ow = ow.to(device=dev, non_blocking=True)
|
||||
kmx = w[f"{att}key.weight_mx"] if wtype == torch.uint8 else x
|
||||
krx = w[f"{att}key.weight_rx"] if wtype == torch.uint8 else x
|
||||
kmy = w[f"{att}key.weight_my"] if wtype == torch.uint8 else x
|
||||
kry = w[f"{att}key.weight_ry"] if wtype == torch.uint8 else x
|
||||
vmx = w[f"{att}value.weight_mx"] if wtype == torch.uint8 else x
|
||||
vrx = w[f"{att}value.weight_rx"] if wtype == torch.uint8 else x
|
||||
vmy = w[f"{att}value.weight_my"] if wtype == torch.uint8 else x
|
||||
vry = w[f"{att}value.weight_ry"] if wtype == torch.uint8 else x
|
||||
rmx = w[f"{att}receptance.weight_mx"] if wtype == torch.uint8 else x
|
||||
rrx = w[f"{att}receptance.weight_rx"] if wtype == torch.uint8 else x
|
||||
rmy = w[f"{att}receptance.weight_my"] if wtype == torch.uint8 else x
|
||||
rry = w[f"{att}receptance.weight_ry"] if wtype == torch.uint8 else x
|
||||
omx = w[f"{att}output.weight_mx"] if wtype == torch.uint8 else x
|
||||
orx = w[f"{att}output.weight_rx"] if wtype == torch.uint8 else x
|
||||
omy = w[f"{att}output.weight_my"] if wtype == torch.uint8 else x
|
||||
ory = w[f"{att}output.weight_ry"] if wtype == torch.uint8 else x
|
||||
(
|
||||
x,
|
||||
state[i * 5 + 0],
|
||||
state[i * 5 + 1],
|
||||
state[i * 5 + 2],
|
||||
state[i * 5 + 3],
|
||||
) = ATT(
|
||||
x,
|
||||
state[i * 5 + 0],
|
||||
state[i * 5 + 1],
|
||||
state[i * 5 + 2],
|
||||
state[i * 5 + 3],
|
||||
w[f"{bbb}ln1.weight"],
|
||||
w[f"{bbb}ln1.bias"],
|
||||
w[f"{att}time_mix_k"],
|
||||
w[f"{att}time_mix_v"],
|
||||
w[f"{att}time_mix_r"],
|
||||
w[f"{att}time_decay"],
|
||||
w[f"{att}time_first"],
|
||||
kw,
|
||||
vw,
|
||||
rw,
|
||||
ow,
|
||||
kmx,
|
||||
krx,
|
||||
kmy,
|
||||
kry,
|
||||
vmx,
|
||||
vrx,
|
||||
vmy,
|
||||
vry,
|
||||
rmx,
|
||||
rrx,
|
||||
rmy,
|
||||
rry,
|
||||
omx,
|
||||
orx,
|
||||
omy,
|
||||
ory,
|
||||
)
|
||||
|
||||
return state[0].tolist(), token_len
|
||||
|
||||
def generate(self, prompt: str, stop: str = None):
|
||||
quick_log(None, None, "Generation Prompt:\n" + prompt)
|
||||
cache = None
|
||||
delta_prompt = prompt
|
||||
try:
|
||||
cache = state_cache.longest_prefix_state(
|
||||
state_cache.LongestPrefixStateBody(prompt=prompt), None
|
||||
)
|
||||
except HTTPException:
|
||||
pass
|
||||
if cache is None or cache["prompt"] == "":
|
||||
self.model_state = None
|
||||
self.model_tokens = []
|
||||
else:
|
||||
delta_prompt = prompt[len(cache["prompt"]) :]
|
||||
self.model_state = copy.deepcopy(cache["state"])
|
||||
self.model_tokens = copy.deepcopy(cache["tokens"])
|
||||
logits = copy.deepcopy(cache["logits"])
|
||||
|
||||
prompt_token_len = 0
|
||||
if delta_prompt != "":
|
||||
logits, prompt_token_len = self.run_rnn(
|
||||
self.fix_tokens(self.pipeline.encode(delta_prompt))
|
||||
)
|
||||
try:
|
||||
state_cache.add_state(
|
||||
state_cache.AddStateBody(
|
||||
prompt=prompt,
|
||||
tokens=self.model_tokens,
|
||||
state=self.model_state,
|
||||
logits=logits,
|
||||
)
|
||||
)
|
||||
except HTTPException:
|
||||
pass
|
||||
|
||||
begin = len(self.model_tokens)
|
||||
out_last = begin
|
||||
|
||||
occurrence: Dict = {}
|
||||
|
||||
completion_token_len = 0
|
||||
response = ""
|
||||
for i in range(self.max_tokens_per_generation):
|
||||
for n in occurrence:
|
||||
logits[n] -= (
|
||||
self.penalty_alpha_presence
|
||||
+ occurrence[n] * self.penalty_alpha_frequency
|
||||
)
|
||||
token = self.pipeline.sample_logits(
|
||||
logits, temperature=self.temperature, top_p=self.top_p
|
||||
)
|
||||
|
||||
if token == END_OF_TEXT:
|
||||
yield response, "", prompt_token_len, completion_token_len
|
||||
break
|
||||
for xxx in occurrence:
|
||||
occurrence[xxx] *= 0.996
|
||||
if token not in occurrence:
|
||||
occurrence[token] = 1
|
||||
else:
|
||||
occurrence[token] += 1
|
||||
|
||||
logits, _ = self.run_rnn([token])
|
||||
completion_token_len = completion_token_len + 1
|
||||
delta: str = self.pipeline.decode(self.model_tokens[out_last:])
|
||||
if "\ufffd" not in delta: # avoid utf-8 display issues
|
||||
response += delta
|
||||
if stop is not None:
|
||||
if stop in response:
|
||||
try:
|
||||
state_cache.add_state(
|
||||
state_cache.AddStateBody(
|
||||
prompt=prompt + response,
|
||||
tokens=self.model_tokens,
|
||||
state=self.model_state,
|
||||
logits=logits,
|
||||
)
|
||||
)
|
||||
except HTTPException:
|
||||
pass
|
||||
response = response.split(stop)[0]
|
||||
yield response, "", prompt_token_len, completion_token_len
|
||||
break
|
||||
out_last = begin + i + 1
|
||||
if i == self.max_tokens_per_generation - 1:
|
||||
try:
|
||||
state_cache.add_state(
|
||||
state_cache.AddStateBody(
|
||||
prompt=prompt + response,
|
||||
tokens=self.model_tokens,
|
||||
state=self.model_state,
|
||||
logits=logits,
|
||||
)
|
||||
)
|
||||
except HTTPException:
|
||||
pass
|
||||
yield response, delta, prompt_token_len, completion_token_len
|
||||
|
||||
|
||||
class ModelConfigBody(BaseModel):
|
||||
max_tokens: int = None
|
||||
temperature: float = None
|
||||
top_p: float = None
|
||||
presence_penalty: float = None
|
||||
frequency_penalty: float = None
|
||||
max_tokens: int = Field(default=None, gt=0, le=102400)
|
||||
temperature: float = Field(default=None, ge=0, le=2)
|
||||
top_p: float = Field(default=None, ge=0, le=1)
|
||||
presence_penalty: float = Field(default=None, ge=-2, le=2)
|
||||
frequency_penalty: float = Field(default=None, ge=-2, le=2)
|
||||
|
||||
class Config:
|
||||
schema_extra = {
|
||||
"example": {
|
||||
"max_tokens": 1000,
|
||||
"temperature": 1.2,
|
||||
"top_p": 0.5,
|
||||
"presence_penalty": 0.4,
|
||||
"frequency_penalty": 0.4,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def set_rwkv_config(model: RWKV, body: ModelConfigBody):
|
||||
if body.max_tokens:
|
||||
if body.max_tokens is not None:
|
||||
model.max_tokens_per_generation = body.max_tokens
|
||||
if body.temperature:
|
||||
model.temperature = body.temperature
|
||||
if body.top_p:
|
||||
if body.temperature is not None:
|
||||
if body.temperature < 0.1:
|
||||
model.temperature = 0.1
|
||||
else:
|
||||
model.temperature = body.temperature
|
||||
if body.top_p is not None:
|
||||
model.top_p = body.top_p
|
||||
if body.presence_penalty:
|
||||
if body.presence_penalty is not None:
|
||||
model.penalty_alpha_presence = body.presence_penalty
|
||||
if body.frequency_penalty:
|
||||
if body.frequency_penalty is not None:
|
||||
model.penalty_alpha_frequency = body.frequency_penalty
|
||||
|
||||
|
||||
@@ -34,49 +403,3 @@ def get_rwkv_config(model: RWKV) -> ModelConfigBody:
|
||||
presence_penalty=model.penalty_alpha_presence,
|
||||
frequency_penalty=model.penalty_alpha_frequency,
|
||||
)
|
||||
|
||||
|
||||
os.environ["TORCH_EXTENSIONS_DIR"] = f"{pathlib.Path(__file__).parent.parent.resolve()}"
|
||||
|
||||
|
||||
def rwkv_generate(model: RWKV, prompt: str, stop: str = None):
|
||||
model.model_state = None
|
||||
model.model_tokens = []
|
||||
logits = model.run_rnn(model.tokenizer.encode(prompt).ids)
|
||||
begin = len(model.model_tokens)
|
||||
out_last = begin
|
||||
|
||||
occurrence: Dict = {}
|
||||
|
||||
response = ""
|
||||
for i in range(model.max_tokens_per_generation):
|
||||
for n in occurrence:
|
||||
logits[n] -= (
|
||||
model.penalty_alpha_presence
|
||||
+ occurrence[n] * model.penalty_alpha_frequency
|
||||
)
|
||||
token = model.pipeline.sample_logits(
|
||||
logits, temperature=model.temperature, top_p=model.top_p
|
||||
)
|
||||
|
||||
END_OF_TEXT = 0
|
||||
if token == END_OF_TEXT:
|
||||
break
|
||||
if token not in occurrence:
|
||||
occurrence[token] = 1
|
||||
else:
|
||||
occurrence[token] += 1
|
||||
|
||||
logits = model.run_rnn([token])
|
||||
delta: str = model.tokenizer.decode(model.model_tokens[out_last:])
|
||||
if "\ufffd" not in delta: # avoid utf-8 display issues
|
||||
response += delta
|
||||
if stop is not None:
|
||||
if stop in response:
|
||||
response = response.split(stop)[0]
|
||||
yield response, ""
|
||||
break
|
||||
yield response, delta
|
||||
out_last = begin + i + 1
|
||||
if i >= model.max_tokens_per_generation - 100:
|
||||
break
|
||||
|
||||
BIN
backend-python/wkv_cuda_utils/wkv_cuda40.pyd
vendored
BIN
build/appicon.png
vendored
|
Before Width: | Height: | Size: 102 KiB After Width: | Height: | Size: 83 KiB |
2
build/darwin/Info.dev.plist
vendored
@@ -8,7 +8,7 @@
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>{{.Name}}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.wails.{{.Name}}</string>
|
||||
<string>dev.josStorer.RWKV-Runner</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>{{.Info.ProductVersion}}</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
|
||||
2
build/darwin/Info.plist
vendored
@@ -8,7 +8,7 @@
|
||||
<key>CFBundleExecutable</key>
|
||||
<string>{{.Name}}</string>
|
||||
<key>CFBundleIdentifier</key>
|
||||
<string>com.wails.{{.Name}}</string>
|
||||
<string>dev.josStorer.RWKV-Runner</string>
|
||||
<key>CFBundleVersion</key>
|
||||
<string>{{.Info.ProductVersion}}</string>
|
||||
<key>CFBundleGetInfoString</key>
|
||||
|
||||
13
build/darwin/Readme_Install.txt
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
For Mac and Linux users, please manually install Python 3.10 (usually the latest systems come with it built-in). You can specify the Python interpreter to use in Settings.
|
||||
对于Mac和Linux用户,请手动安装 Python3.10 (通常最新的系统已经内置了). 你可以在设置中指定使用的Python解释器.
|
||||
MacおよびLinuxのユーザーの方は、Python3.10を手動でインストールしてください(通常、最新のシステムには既に組み込まれています)。 設定メニューで使用するPythonインタプリタを指定することができます。
|
||||
|
||||
Please execute this program in an empty directory. All related dependencies will be placed in this directory.
|
||||
请将本程序放在一个空目录内执行, 所有相关依赖均会放置于此目录.
|
||||
このプログラムを空のディレクトリで実行してください。関連するすべての依存関係は、このディレクトリに配置されます。
|
||||
|
||||
Please execute the following command in the terminal to remove the permission restrictions of this app, and then this program can work properly:
|
||||
请在终端执行以下命令解除本app的权限限制, 然后本程序才可以正常工作:
|
||||
このアプリの権限制限を解除するために、ターミナルで以下のコマンドを実行してください。その後、このプログラムは正常に動作するようになります:
|
||||
|
||||
sudo xattr -r -d com.apple.quarantine ./RWKV-Runner.app
|
||||
16
build/darwin/entitlements.plist
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>com.apple.security.app-sandbox</key>
|
||||
<false/>
|
||||
<key>com.apple.security.network.client</key>
|
||||
<true/>
|
||||
<key>com.apple.security.network.server</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.user-selected.read-write</key>
|
||||
<true/>
|
||||
<key>com.apple.security.files.downloads.read-write</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
17
build/darwin/gon-sign.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"source": [
|
||||
"./build/bin/RWKV-Runner_darwin.app"
|
||||
],
|
||||
"bundle_id": "dev.josStorer.RWKV-Runner",
|
||||
"apple_id": {
|
||||
"username": "joshua1466587594@outlook.com",
|
||||
"password": ""
|
||||
},
|
||||
"sign": {
|
||||
"application_identity": "D00A983569B4EAA2A008B963254F385F42A493FD",
|
||||
"entitlements_file": "./build/darwin/entitlements.plist"
|
||||
},
|
||||
"zip": {
|
||||
"output_path": "./build/bin/RWKV-Runner_darwin.archive.zip"
|
||||
}
|
||||
}
|
||||
19
build/linux/Readme_Install.txt
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
For Mac and Linux users, please manually install Python 3.10 (usually the latest systems come with it built-in). You can specify the Python interpreter to use in Settings.
|
||||
对于Mac和Linux用户,请手动安装 Python3.10 (通常最新的系统已经内置了). 你可以在设置中指定使用的Python解释器.
|
||||
MacおよびLinuxのユーザーの方は、Python3.10を手動でインストールしてください(通常、最新のシステムには既に組み込まれています)。 設定メニューで使用するPythonインタプリタを指定することができます。
|
||||
|
||||
Please execute this program in an empty directory. All related dependencies will be placed in this directory.
|
||||
请将本程序放在一个空目录内执行, 所有相关依赖均会放置于此目录.
|
||||
このプログラムを空のディレクトリで実行してください。関連するすべての依存関係は、このディレクトリに配置されます。
|
||||
|
||||
On Linux system, this program cannot invoke the terminal for automatic dependency installation. You must manually execute the following commands for installation so that it can be used normally:
|
||||
在Linux系统下, 本程序无法调用终端自动安装依赖, 你必须手动执行以下命令进行安装, 之后方可正常使用:
|
||||
Linuxシステムでは、このプログラムはターミナルを自動的に呼び出して依存関係をインストールすることができません。以下のコマンドを手動で実行する必要があります。それが完了した後に、正常に使用することができます:
|
||||
|
||||
sudo apt install python3-dev
|
||||
chmod +x ./RWKV-Runner
|
||||
./RWKV-Runner
|
||||
cd backend-python
|
||||
pip3 install -r requirements.txt # or pip3 install -r requirements_without_cyac.txt
|
||||
|
||||
# See More: https://github.com/josStorer/RWKV-Runner/tree/master/deploy-examples
|
||||
3
build/windows/Readme_Install.txt
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
Please execute this program in an empty directory. All related dependencies will be placed in this directory.
|
||||
请将本程序放在一个空目录内执行, 所有相关依赖均会放置于此目录.
|
||||
このプログラムを空のディレクトリで実行してください。関連するすべての依存関係は、このディレクトリに配置されます。
|
||||
BIN
build/windows/icon.ico
vendored
|
Before Width: | Height: | Size: 147 KiB After Width: | Height: | Size: 175 KiB |
24
deploy-examples/ChatGPT-Next-Web/setup.bat
Normal file
@@ -0,0 +1,24 @@
|
||||
: install git python3.10 yarn by yourself
|
||||
: change model and strategy according to your hardware
|
||||
|
||||
mkdir RWKV-Next-Web
|
||||
cd RWKV-Next-Web
|
||||
|
||||
git clone https://github.com/josStorer/RWKV-Runner --depth=1
|
||||
python -m pip install torch==1.13.1 torchvision==0.14.1 torchaudio==0.13.1 --index-url https://download.pytorch.org/whl/cu117
|
||||
python -m pip install -r RWKV-Runner/backend-python/requirements.txt
|
||||
start python ./RWKV-Runner/backend-python/main.py
|
||||
|
||||
powershell -Command "(Test-Path ./RWKV-Runner/models) -or (mkdir RWKV-Runner/models)"
|
||||
powershell -Command "Import-Module BitsTransfer"
|
||||
powershell -Command "(Test-Path ./RWKV-Runner/models/RWKV-4-World-1.5B-v1-fixed-20230612-ctx4096.pth) -or (Start-BitsTransfer https://huggingface.co/BlinkDL/rwkv-4-world/resolve/main/RWKV-4-World-1.5B-v1-fixed-20230612-ctx4096.pth ./RWKV-Runner/models/RWKV-4-World-1.5B-v1-fixed-20230612-ctx4096.pth)"
|
||||
powershell -Command "Invoke-WebRequest http://127.0.0.1:8000/switch-model -Method POST -ContentType 'application/json' -Body '{\"model\":\"./RWKV-Runner/models/RWKV-4-World-1.5B-v1-fixed-20230612-ctx4096.pth\",\"strategy\":\"cuda fp32 *20+\"}'"
|
||||
|
||||
git clone https://github.com/Yidadaa/ChatGPT-Next-Web --depth=1
|
||||
cd ChatGPT-Next-Web
|
||||
call yarn install
|
||||
call yarn build
|
||||
set PROXY_URL=""
|
||||
set BASE_URL=http://127.0.0.1:8000
|
||||
start "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" "http://127.0.0.1:3000"
|
||||
yarn start
|
||||
27
deploy-examples/ChatGPT-Next-Web/setup.sh
Normal file
@@ -0,0 +1,27 @@
|
||||
# install git python3.10 yarn by yourself
|
||||
# change model and strategy according to your hardware
|
||||
|
||||
sudo apt install python3-dev
|
||||
|
||||
mkdir RWKV-Next-Web
|
||||
cd RWKV-Next-Web
|
||||
|
||||
git clone https://github.com/josStorer/RWKV-Runner --depth=1
|
||||
python3 -m pip install torch torchvision torchaudio
|
||||
python3 -m pip install -r RWKV-Runner/backend-python/requirements.txt
|
||||
python3 ./RWKV-Runner/backend-python/main.py > log.txt &
|
||||
|
||||
if [ ! -d RWKV-Runner/models ]; then
|
||||
mkdir RWKV-Runner/models
|
||||
fi
|
||||
wget -N https://huggingface.co/BlinkDL/rwkv-4-world/resolve/main/RWKV-4-World-0.1B-v1-20230520-ctx4096.pth -P RWKV-Runner/models/
|
||||
|
||||
git clone https://github.com/Yidadaa/ChatGPT-Next-Web --depth=1
|
||||
cd ChatGPT-Next-Web
|
||||
yarn install
|
||||
yarn build
|
||||
export PROXY_URL=""
|
||||
export BASE_URL=http://127.0.0.1:8000
|
||||
yarn start &
|
||||
|
||||
curl http://127.0.0.1:8000/switch-model -X POST -H "Content-Type: application/json" -d '{"model":"./RWKV-Runner/models/RWKV-4-World-0.1B-v1-20230520-ctx4096.pth","strategy":"cpu fp32"}'
|
||||
7
finetune/data/sample.jsonl
Normal file
@@ -0,0 +1,7 @@
|
||||
{"text": "1:This is the first document."}
|
||||
{"text": "2:Hello\nWorld"}
|
||||
{"text": "3:1+1=2\n1+2=3\n2+2=4"}
|
||||
{"text": "4:You will be training the GPT version because it's paralleziable and faster to train."}
|
||||
{"text": "5:Read the inference code in src/model.py and try using the final hidden state(.xx .aa .bb)"}
|
||||
{"text": "6:You can fine-tune the model with longer ctxLen and it can quickly adapt to longer ctxLens."}
|
||||
{"text": "7:Consider RWKV 14B. The state has 200 vectors, that is, 5 vectors for each block: fp16 (xx), fp32 (aa), fp32 (bb), fp32 (pp), fp16 (xx)."}
|
||||
41
finetune/get_layer_and_embd.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import torch
|
||||
import sys
|
||||
import time
|
||||
import os
|
||||
import threading
|
||||
import gc
|
||||
|
||||
|
||||
def file_cleaner(file):
|
||||
last_pos = 0
|
||||
|
||||
def cleaner():
|
||||
nonlocal last_pos
|
||||
while True:
|
||||
time.sleep(0.1)
|
||||
pos = file.tell()
|
||||
if pos > last_pos:
|
||||
os.posix_fadvise(
|
||||
file.fileno(), last_pos, pos - last_pos, os.POSIX_FADV_DONTNEED
|
||||
)
|
||||
last_pos = pos
|
||||
|
||||
return cleaner
|
||||
|
||||
|
||||
model_file = open(sys.argv[1], "rb")
|
||||
cleaner = file_cleaner(model_file)
|
||||
cleaner_thread = threading.Thread(target=cleaner, daemon=True)
|
||||
cleaner_thread.start()
|
||||
|
||||
w = torch.load(model_file, map_location="cpu")
|
||||
gc.collect()
|
||||
|
||||
n_embd = w["emb.weight"].shape[1]
|
||||
n_layer = 0
|
||||
keys = list(w.keys())
|
||||
for x in keys:
|
||||
layer_id = int(x.split(".")[1]) if ("blocks." in x) else 0
|
||||
n_layer = max(n_layer, layer_id + 1)
|
||||
|
||||
print(f"--n_layer {n_layer} --n_embd {n_embd}", end="")
|
||||
52
finetune/install-wsl-dep-and-train.sh
Normal file
@@ -0,0 +1,52 @@
|
||||
if [[ ${cnMirror} == 1 ]]; then
|
||||
export PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
if grep -q "mirrors.aliyun.com" /etc/apt/sources.list; then
|
||||
echo "apt cnMirror already set"
|
||||
else
|
||||
sudo sed -i 's/http:\/\/archive.ubuntu.com\/ubuntu\//http:\/\/mirrors.aliyun.com\/ubuntu\//g' /etc/apt/sources.list
|
||||
sudo apt update
|
||||
fi
|
||||
fi
|
||||
|
||||
if dpkg -s "gcc" >/dev/null 2>&1; then
|
||||
echo "gcc installed"
|
||||
else
|
||||
sudo apt -y install gcc
|
||||
fi
|
||||
|
||||
if dpkg -s "python3-pip" >/dev/null 2>&1; then
|
||||
echo "pip installed"
|
||||
else
|
||||
sudo apt -y install python3-pip
|
||||
fi
|
||||
|
||||
if dpkg -s "ninja-build" >/dev/null 2>&1; then
|
||||
echo "ninja installed"
|
||||
else
|
||||
sudo apt -y install ninja-build
|
||||
fi
|
||||
|
||||
if dpkg -s "cuda" >/dev/null 2>&1 && dpkg -s "cuda" | grep Version | awk '{print $2}' | grep -q "12"; then
|
||||
echo "cuda 12 installed"
|
||||
else
|
||||
wget -N https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
|
||||
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
|
||||
wget -N https://developer.download.nvidia.com/compute/cuda/12.2.0/local_installers/cuda-repo-wsl-ubuntu-12-2-local_12.2.0-1_amd64.deb
|
||||
sudo dpkg -i cuda-repo-wsl-ubuntu-12-2-local_12.2.0-1_amd64.deb
|
||||
sudo cp /var/cuda-repo-wsl-ubuntu-12-2-local/cuda-*-keyring.gpg /usr/share/keyrings/
|
||||
sudo apt-get update
|
||||
sudo apt-get -y install cuda
|
||||
fi
|
||||
|
||||
if python3 -c "import pkg_resources; pkg_resources.require(open('./finetune/requirements.txt',mode='r'))" &>/dev/null; then
|
||||
echo "requirements satisfied"
|
||||
else
|
||||
python3 -m pip install -r ./finetune/requirements.txt
|
||||
fi
|
||||
|
||||
echo "loading $loadModel"
|
||||
modelInfo=$(python3 ./finetune/get_layer_and_embd.py $loadModel)
|
||||
echo $modelInfo
|
||||
|
||||
python3 ./finetune/lora/train.py $modelInfo $@ --proj_dir lora-models --data_type binidx --lora \
|
||||
--lora_parts=att,ffn,time,ln --strategy deepspeed_stage_2 --accelerator gpu
|
||||
597
finetune/json2binidx_tool/tools/indexed_dataset.py
vendored
Normal file
@@ -0,0 +1,597 @@
|
||||
# Copyright (c) 2021, EleutherAI
|
||||
# This file is based on code by the authors denoted below and has been modified from its original version.
|
||||
#
|
||||
# Copyright (c) Facebook, Inc. and its affiliates.
|
||||
#
|
||||
# This source code is licensed under the MIT license found in the
|
||||
# LICENSE file in the root directory of this source tree.
|
||||
|
||||
|
||||
# copied from fairseq/fairseq/data/indexed_dataset.py
|
||||
# Removed IndexedRawTextDataset since it relied on Fairseq dictionary
|
||||
# other slight modifications to remove fairseq dependencies
|
||||
# Added document index to index file and made it accessible.
|
||||
# An empty sentence no longer separates documents.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import struct
|
||||
from functools import lru_cache
|
||||
from itertools import accumulate
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
|
||||
|
||||
|
||||
|
||||
def __best_fitting_dtype(vocab_size=None):
|
||||
if vocab_size is not None and vocab_size < 65500:
|
||||
return np.uint16
|
||||
else:
|
||||
return np.int32
|
||||
|
||||
|
||||
def infer_dataset_impl(path):
|
||||
if IndexedDataset.exists(path):
|
||||
with open(index_file_path(path), "rb") as f:
|
||||
magic = f.read(8)
|
||||
if magic == IndexedDataset._HDR_MAGIC:
|
||||
return "cached"
|
||||
elif magic == MMapIndexedDataset.Index._HDR_MAGIC[:8]:
|
||||
return "mmap"
|
||||
else:
|
||||
return None
|
||||
else:
|
||||
print(f"Dataset does not exist: {path}")
|
||||
print(
|
||||
"Path should be a basename that both .idx and .bin can be appended to get full filenames."
|
||||
)
|
||||
return None
|
||||
|
||||
|
||||
def make_builder(out_file, impl, vocab_size=None):
|
||||
if impl == "mmap":
|
||||
return MMapIndexedDatasetBuilder(
|
||||
out_file, dtype=__best_fitting_dtype(vocab_size)
|
||||
)
|
||||
else:
|
||||
return IndexedDatasetBuilder(out_file)
|
||||
|
||||
|
||||
def make_dataset(path, impl, skip_warmup=False):
|
||||
if not IndexedDataset.exists(path):
|
||||
print(f"Dataset does not exist: {path}")
|
||||
print(
|
||||
"Path should be a basename that both .idx and .bin can be appended to get full filenames."
|
||||
)
|
||||
return None
|
||||
if impl == "infer":
|
||||
impl = infer_dataset_impl(path)
|
||||
if impl == "lazy" and IndexedDataset.exists(path):
|
||||
return IndexedDataset(path)
|
||||
elif impl == "cached" and IndexedDataset.exists(path):
|
||||
return IndexedCachedDataset(path)
|
||||
elif impl == "mmap" and MMapIndexedDataset.exists(path):
|
||||
return MMapIndexedDataset(path, skip_warmup)
|
||||
print(f"Unknown dataset implementation: {impl}")
|
||||
return None
|
||||
|
||||
|
||||
def dataset_exists(path, impl):
|
||||
if impl == "mmap":
|
||||
return MMapIndexedDataset.exists(path)
|
||||
else:
|
||||
return IndexedDataset.exists(path)
|
||||
|
||||
|
||||
def read_longs(f, n):
|
||||
a = np.empty(n, dtype=np.int64)
|
||||
f.readinto(a)
|
||||
return a
|
||||
|
||||
|
||||
def write_longs(f, a):
|
||||
f.write(np.array(a, dtype=np.int64))
|
||||
|
||||
|
||||
dtypes = {
|
||||
1: np.uint8,
|
||||
2: np.int8,
|
||||
3: np.int16,
|
||||
4: np.int32,
|
||||
5: np.int64,
|
||||
6: np.float32,
|
||||
7: np.float64,
|
||||
8: np.uint16,
|
||||
}
|
||||
|
||||
|
||||
def code(dtype):
|
||||
for k in dtypes.keys():
|
||||
if dtypes[k] == dtype:
|
||||
return k
|
||||
raise ValueError(dtype)
|
||||
|
||||
|
||||
def index_file_path(prefix_path):
|
||||
return prefix_path + ".idx"
|
||||
|
||||
|
||||
def data_file_path(prefix_path):
|
||||
return prefix_path + ".bin"
|
||||
|
||||
|
||||
def create_doc_idx(sizes):
|
||||
doc_idx = [0]
|
||||
for i, s in enumerate(sizes):
|
||||
if s == 0:
|
||||
doc_idx.append(i + 1)
|
||||
return doc_idx
|
||||
|
||||
|
||||
class IndexedDataset(torch.utils.data.Dataset):
|
||||
"""Loader for IndexedDataset"""
|
||||
|
||||
_HDR_MAGIC = b"TNTIDX\x00\x00"
|
||||
|
||||
def __init__(self, path):
|
||||
super().__init__()
|
||||
self.path = path
|
||||
self.data_file = None
|
||||
self.read_index(path)
|
||||
|
||||
def read_index(self, path):
|
||||
with open(index_file_path(path), "rb") as f:
|
||||
magic = f.read(8)
|
||||
assert magic == self._HDR_MAGIC, (
|
||||
"Index file doesn't match expected format. "
|
||||
"Make sure that --dataset-impl is configured properly."
|
||||
)
|
||||
version = f.read(8)
|
||||
assert struct.unpack("<Q", version) == (1,)
|
||||
code, self.element_size = struct.unpack("<QQ", f.read(16))
|
||||
self.dtype = dtypes[code]
|
||||
self._len, self.s = struct.unpack("<QQ", f.read(16))
|
||||
self.doc_count = struct.unpack("<Q", f.read(8))
|
||||
self.dim_offsets = read_longs(f, self._len + 1)
|
||||
self.data_offsets = read_longs(f, self._len + 1)
|
||||
self.sizes = read_longs(f, self.s)
|
||||
self.doc_idx = read_longs(f, self.doc_count)
|
||||
|
||||
def read_data(self, path):
|
||||
self.data_file = open(data_file_path(path), "rb", buffering=0)
|
||||
|
||||
def check_index(self, i):
|
||||
if i < 0 or i >= self._len:
|
||||
raise IndexError("index out of range")
|
||||
|
||||
def __del__(self):
|
||||
if self.data_file:
|
||||
self.data_file.close()
|
||||
|
||||
# @lru_cache(maxsize=8)
|
||||
def __getitem__(self, idx):
|
||||
if not self.data_file:
|
||||
self.read_data(self.path)
|
||||
if isinstance(idx, int):
|
||||
i = idx
|
||||
self.check_index(i)
|
||||
tensor_size = self.sizes[self.dim_offsets[i] : self.dim_offsets[i + 1]]
|
||||
a = np.empty(tensor_size, dtype=self.dtype)
|
||||
self.data_file.seek(self.data_offsets[i] * self.element_size)
|
||||
self.data_file.readinto(a)
|
||||
return a
|
||||
elif isinstance(idx, slice):
|
||||
start, stop, step = idx.indices(len(self))
|
||||
if step != 1:
|
||||
raise ValueError("Slices into indexed_dataset must be contiguous")
|
||||
sizes = self.sizes[self.dim_offsets[start] : self.dim_offsets[stop]]
|
||||
size = sum(sizes)
|
||||
a = np.empty(size, dtype=self.dtype)
|
||||
self.data_file.seek(self.data_offsets[start] * self.element_size)
|
||||
self.data_file.readinto(a)
|
||||
offsets = list(accumulate(sizes))
|
||||
sents = np.split(a, offsets[:-1])
|
||||
return sents
|
||||
|
||||
def __len__(self):
|
||||
return self._len
|
||||
|
||||
def num_tokens(self, index):
|
||||
return self.sizes[index]
|
||||
|
||||
def size(self, index):
|
||||
return self.sizes[index]
|
||||
|
||||
@staticmethod
|
||||
def exists(path):
|
||||
return os.path.exists(index_file_path(path)) and os.path.exists(
|
||||
data_file_path(path)
|
||||
)
|
||||
|
||||
@property
|
||||
def supports_prefetch(self):
|
||||
return False # avoid prefetching to save memory
|
||||
|
||||
|
||||
class IndexedCachedDataset(IndexedDataset):
|
||||
def __init__(self, path):
|
||||
super().__init__(path)
|
||||
self.cache = None
|
||||
self.cache_index = {}
|
||||
|
||||
@property
|
||||
def supports_prefetch(self):
|
||||
return True
|
||||
|
||||
def prefetch(self, indices):
|
||||
if all(i in self.cache_index for i in indices):
|
||||
return
|
||||
if not self.data_file:
|
||||
self.read_data(self.path)
|
||||
indices = sorted(set(indices))
|
||||
total_size = 0
|
||||
for i in indices:
|
||||
total_size += self.data_offsets[i + 1] - self.data_offsets[i]
|
||||
self.cache = np.empty(total_size, dtype=self.dtype)
|
||||
ptx = 0
|
||||
self.cache_index.clear()
|
||||
for i in indices:
|
||||
self.cache_index[i] = ptx
|
||||
size = self.data_offsets[i + 1] - self.data_offsets[i]
|
||||
a = self.cache[ptx : ptx + size]
|
||||
self.data_file.seek(self.data_offsets[i] * self.element_size)
|
||||
self.data_file.readinto(a)
|
||||
ptx += size
|
||||
if self.data_file:
|
||||
# close and delete data file after prefetch so we can pickle
|
||||
self.data_file.close()
|
||||
self.data_file = None
|
||||
|
||||
# @lru_cache(maxsize=8)
|
||||
def __getitem__(self, idx):
|
||||
if isinstance(idx, int):
|
||||
i = idx
|
||||
self.check_index(i)
|
||||
tensor_size = self.sizes[self.dim_offsets[i] : self.dim_offsets[i + 1]]
|
||||
a = np.empty(tensor_size, dtype=self.dtype)
|
||||
ptx = self.cache_index[i]
|
||||
np.copyto(a, self.cache[ptx : ptx + a.size])
|
||||
return a
|
||||
elif isinstance(idx, slice):
|
||||
# Hack just to make this work, can optimizer later if necessary
|
||||
sents = []
|
||||
for i in range(*idx.indices(len(self))):
|
||||
sents.append(self[i])
|
||||
return sents
|
||||
|
||||
|
||||
class IndexedDatasetBuilder(object):
|
||||
element_sizes = {
|
||||
np.uint8: 1,
|
||||
np.int8: 1,
|
||||
np.int16: 2,
|
||||
np.int32: 4,
|
||||
np.int64: 8,
|
||||
np.float32: 4,
|
||||
np.float64: 8,
|
||||
}
|
||||
|
||||
def __init__(self, out_file, dtype=np.int32):
|
||||
self.out_file = open(out_file, "wb")
|
||||
self.dtype = dtype
|
||||
self.data_offsets = [0]
|
||||
self.dim_offsets = [0]
|
||||
self.sizes = []
|
||||
self.element_size = self.element_sizes[self.dtype]
|
||||
self.doc_idx = [0]
|
||||
|
||||
def add_item(self, np_array):
|
||||
assert isinstance(np_array, np.ndarray) and np_array.dtype == self.dtype
|
||||
bytes = self.out_file.write(np_array)
|
||||
self.data_offsets.append(self.data_offsets[-1] + bytes / self.element_size)
|
||||
for s in np_array.shape:
|
||||
self.sizes.append(s)
|
||||
self.dim_offsets.append(self.dim_offsets[-1] + len(np_array.shape))
|
||||
|
||||
def end_document(self):
|
||||
self.doc_idx.append(len(self.sizes))
|
||||
|
||||
def merge_file_(self, another_file):
|
||||
index = IndexedDataset(another_file)
|
||||
assert index.dtype == self.dtype
|
||||
|
||||
begin = self.data_offsets[-1]
|
||||
for offset in index.data_offsets[1:]:
|
||||
self.data_offsets.append(begin + offset)
|
||||
self.sizes.extend(index.sizes)
|
||||
begin = self.dim_offsets[-1]
|
||||
for dim_offset in index.dim_offsets[1:]:
|
||||
self.dim_offsets.append(begin + dim_offset)
|
||||
|
||||
with open(data_file_path(another_file), "rb") as f:
|
||||
while True:
|
||||
data = f.read(1024)
|
||||
if data:
|
||||
self.out_file.write(data)
|
||||
else:
|
||||
break
|
||||
|
||||
def finalize(self, index_file):
|
||||
self.out_file.close()
|
||||
index = open(index_file, "wb")
|
||||
index.write(b"TNTIDX\x00\x00")
|
||||
index.write(struct.pack("<Q", 1))
|
||||
index.write(struct.pack("<QQ", code(self.dtype), self.element_size))
|
||||
index.write(struct.pack("<QQ", len(self.data_offsets) - 1, len(self.sizes)))
|
||||
index.write(struct.pack("<Q", len(self.doc_idx)))
|
||||
write_longs(index, self.dim_offsets)
|
||||
write_longs(index, self.data_offsets)
|
||||
write_longs(index, self.sizes)
|
||||
write_longs(index, self.doc_idx)
|
||||
index.close()
|
||||
|
||||
|
||||
def _warmup_mmap_file(path):
|
||||
with open(path, "rb") as stream:
|
||||
while stream.read(100 * 1024 * 1024):
|
||||
pass
|
||||
|
||||
|
||||
class MMapIndexedDataset(torch.utils.data.Dataset):
|
||||
class Index(object):
|
||||
_HDR_MAGIC = b"MMIDIDX\x00\x00"
|
||||
|
||||
@classmethod
|
||||
def writer(cls, path, dtype):
|
||||
class _Writer(object):
|
||||
def __enter__(self):
|
||||
self._file = open(path, "wb")
|
||||
|
||||
# Write Magic string so we can check the file format then opening it again.
|
||||
self._file.write(cls._HDR_MAGIC)
|
||||
# Write version number
|
||||
# Little endian unsigned 64 Bit integer
|
||||
self._file.write(struct.pack("<Q", 1))
|
||||
# Little endian unsigned 8 Bit integer
|
||||
self._file.write(struct.pack("<B", code(dtype)))
|
||||
|
||||
return self
|
||||
|
||||
@staticmethod
|
||||
def _get_pointers(sizes):
|
||||
pointers = np.zeros(len(sizes), dtype=np.int64)
|
||||
sizes = np.array(sizes, dtype=np.int64)
|
||||
|
||||
np.cumsum(sizes[:-1], out=pointers[1:])
|
||||
pointers = pointers * dtype().itemsize
|
||||
return pointers
|
||||
|
||||
def write(self, sizes, doc_idx):
|
||||
pointers = self._get_pointers(sizes)
|
||||
|
||||
# Little endian unsigned 64 Bit integer
|
||||
self._file.write(struct.pack("<Q", len(sizes)))
|
||||
# Little endian unsigned 64 Bit integer
|
||||
self._file.write(struct.pack("<Q", len(doc_idx)))
|
||||
|
||||
sizes = np.array(sizes, dtype=np.int32)
|
||||
self._file.write(sizes.tobytes(order="C"))
|
||||
del sizes
|
||||
|
||||
pointers = np.array(pointers, dtype=np.int64)
|
||||
self._file.write(pointers.tobytes(order="C"))
|
||||
del pointers
|
||||
|
||||
doc_idx = np.array(doc_idx, dtype=np.int64)
|
||||
self._file.write(doc_idx.tobytes(order="C"))
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self._file.close()
|
||||
|
||||
return _Writer()
|
||||
|
||||
def __init__(self, path, skip_warmup=False):
|
||||
with open(path, "rb") as stream:
|
||||
magic_test = stream.read(9)
|
||||
assert self._HDR_MAGIC == magic_test, (
|
||||
"Index file doesn't match expected format. "
|
||||
"Make sure that --dataset-impl is configured properly."
|
||||
)
|
||||
# Little endian unsigned 64 Bit integer
|
||||
version = struct.unpack("<Q", stream.read(8))
|
||||
assert (1,) == version
|
||||
|
||||
# Little endian unsigned 8 Bit integer
|
||||
(dtype_code,) = struct.unpack("<B", stream.read(1))
|
||||
self._dtype = dtypes[dtype_code]
|
||||
self._dtype_size = self._dtype().itemsize
|
||||
|
||||
self._len = struct.unpack("<Q", stream.read(8))[0]
|
||||
self._doc_count = struct.unpack("<Q", stream.read(8))[0]
|
||||
offset = stream.tell()
|
||||
|
||||
if not skip_warmup:
|
||||
print(" warming up index mmap file...")
|
||||
_warmup_mmap_file(path)
|
||||
|
||||
self._bin_buffer_mmap = np.memmap(path, mode="r", order="C")
|
||||
self._bin_buffer = memoryview(self._bin_buffer_mmap)
|
||||
print(" reading sizes...")
|
||||
self._sizes = np.frombuffer(
|
||||
self._bin_buffer, dtype=np.int32, count=self._len, offset=offset
|
||||
)
|
||||
print(" reading pointers...")
|
||||
self._pointers = np.frombuffer(
|
||||
self._bin_buffer,
|
||||
dtype=np.int64,
|
||||
count=self._len,
|
||||
offset=offset + self._sizes.nbytes,
|
||||
)
|
||||
print(" reading document index...")
|
||||
self._doc_idx = np.frombuffer(
|
||||
self._bin_buffer,
|
||||
dtype=np.int64,
|
||||
count=self._doc_count,
|
||||
offset=offset + self._sizes.nbytes + self._pointers.nbytes,
|
||||
)
|
||||
|
||||
def __del__(self):
|
||||
self._bin_buffer_mmap._mmap.close()
|
||||
del self._bin_buffer_mmap
|
||||
|
||||
@property
|
||||
def dtype(self):
|
||||
return self._dtype
|
||||
|
||||
@property
|
||||
def sizes(self):
|
||||
return self._sizes
|
||||
|
||||
@property
|
||||
def doc_idx(self):
|
||||
return self._doc_idx
|
||||
|
||||
@lru_cache(maxsize=8)
|
||||
def __getitem__(self, i):
|
||||
return self._pointers[i], self._sizes[i]
|
||||
|
||||
def __len__(self):
|
||||
return self._len
|
||||
|
||||
def __init__(self, path, skip_warmup=False):
|
||||
super().__init__()
|
||||
|
||||
self._path = None
|
||||
self._index = None
|
||||
self._bin_buffer = None
|
||||
|
||||
self._do_init(path, skip_warmup)
|
||||
|
||||
def __getstate__(self):
|
||||
return self._path
|
||||
|
||||
def __setstate__(self, state):
|
||||
self._do_init(state)
|
||||
|
||||
def _do_init(self, path, skip_warmup):
|
||||
self._path = path
|
||||
self._index = self.Index(index_file_path(self._path), skip_warmup)
|
||||
|
||||
if not skip_warmup:
|
||||
print(" warming up data mmap file...")
|
||||
_warmup_mmap_file(data_file_path(self._path))
|
||||
print(" creating numpy buffer of mmap...")
|
||||
self._bin_buffer_mmap = np.memmap(
|
||||
data_file_path(self._path), mode="r", order="C"
|
||||
)
|
||||
print(" creating memory view of numpy buffer...")
|
||||
self._bin_buffer = memoryview(self._bin_buffer_mmap)
|
||||
|
||||
def __del__(self):
|
||||
self._bin_buffer_mmap._mmap.close()
|
||||
del self._bin_buffer_mmap
|
||||
del self._index
|
||||
|
||||
def __len__(self):
|
||||
return len(self._index)
|
||||
|
||||
# @lru_cache(maxsize=8)
|
||||
def __getitem__(self, idx):
|
||||
if isinstance(idx, int):
|
||||
ptr, size = self._index[idx]
|
||||
np_array = np.frombuffer(
|
||||
self._bin_buffer, dtype=self._index.dtype, count=size, offset=ptr
|
||||
)
|
||||
return np_array
|
||||
elif isinstance(idx, slice):
|
||||
start, stop, step = idx.indices(len(self))
|
||||
if step != 1:
|
||||
raise ValueError("Slices into indexed_dataset must be contiguous")
|
||||
ptr = self._index._pointers[start]
|
||||
sizes = self._index._sizes[idx]
|
||||
offsets = list(accumulate(sizes))
|
||||
total_size = sum(sizes)
|
||||
np_array = np.frombuffer(
|
||||
self._bin_buffer, dtype=self._index.dtype, count=total_size, offset=ptr
|
||||
)
|
||||
sents = np.split(np_array, offsets[:-1])
|
||||
return sents
|
||||
|
||||
def get(self, idx, offset=0, length=None):
|
||||
"""Retrieves a single item from the dataset with the option to only
|
||||
return a portion of the item.
|
||||
|
||||
get(idx) is the same as [idx] but get() does not support slicing.
|
||||
"""
|
||||
ptr, size = self._index[idx]
|
||||
if length is None:
|
||||
length = size - offset
|
||||
ptr += offset * np.dtype(self._index.dtype).itemsize
|
||||
np_array = np.frombuffer(
|
||||
self._bin_buffer, dtype=self._index.dtype, count=length, offset=ptr
|
||||
)
|
||||
return np_array
|
||||
|
||||
@property
|
||||
def sizes(self):
|
||||
return self._index.sizes
|
||||
|
||||
@property
|
||||
def doc_idx(self):
|
||||
return self._index.doc_idx
|
||||
|
||||
def get_doc_idx(self):
|
||||
return self._index._doc_idx
|
||||
|
||||
def set_doc_idx(self, doc_idx_):
|
||||
self._index._doc_idx = doc_idx_
|
||||
|
||||
@property
|
||||
def supports_prefetch(self):
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def exists(path):
|
||||
return os.path.exists(index_file_path(path)) and os.path.exists(
|
||||
data_file_path(path)
|
||||
)
|
||||
|
||||
|
||||
class MMapIndexedDatasetBuilder(object):
|
||||
def __init__(self, out_file, dtype=np.int64):
|
||||
self._data_file = open(out_file, "wb")
|
||||
self._dtype = dtype
|
||||
self._sizes = []
|
||||
self._doc_idx = [0]
|
||||
|
||||
@property
|
||||
def dtype(self):
|
||||
return self._dtype
|
||||
|
||||
def add_item(self, np_array):
|
||||
assert isinstance(np_array, np.ndarray) and np_array.dtype == self.dtype
|
||||
self._data_file.write(np_array.tobytes(order="C"))
|
||||
self._sizes.append(np_array.size)
|
||||
|
||||
def end_document(self):
|
||||
self._doc_idx.append(len(self._sizes))
|
||||
|
||||
def merge_file_(self, another_file):
|
||||
# Concatenate index
|
||||
index = MMapIndexedDataset.Index(index_file_path(another_file))
|
||||
assert index.dtype == self._dtype
|
||||
|
||||
for size in index.sizes:
|
||||
self._sizes.append(size)
|
||||
|
||||
# Concatenate data
|
||||
with open(data_file_path(another_file), "rb") as f:
|
||||
shutil.copyfileobj(f, self._data_file)
|
||||
|
||||
def finalize(self, index_file):
|
||||
self._data_file.close()
|
||||
|
||||
with MMapIndexedDataset.Index.writer(index_file, self._dtype) as index:
|
||||
index.write(self._sizes, self._doc_idx)
|
||||
250
finetune/json2binidx_tool/tools/preprocess_data.py
vendored
Normal file
@@ -0,0 +1,250 @@
|
||||
# Copyright (c) 2021, EleutherAI
|
||||
# This file is based on code by the authors denoted below and has been modified from its original version.
|
||||
#
|
||||
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Processing data for pretraining."""
|
||||
|
||||
import os
|
||||
import sys
|
||||
|
||||
sys.path.append(os.path.dirname(os.path.realpath(__file__)))
|
||||
|
||||
import argparse
|
||||
import multiprocessing
|
||||
|
||||
import lm_dataformat as lmd
|
||||
import numpy as np
|
||||
|
||||
sys.path.append(
|
||||
os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir))
|
||||
)
|
||||
import time
|
||||
import tqdm
|
||||
import ftfy
|
||||
|
||||
from tokenizer import build_tokenizer
|
||||
import indexed_dataset
|
||||
from threading import Semaphore
|
||||
|
||||
|
||||
class Encoder(object):
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
|
||||
def initializer(self):
|
||||
# Use Encoder class as a container for global data
|
||||
Encoder.tokenizer = build_tokenizer(self.args)
|
||||
|
||||
def encode(self, text):
|
||||
if self.args.ftfy:
|
||||
text = ftfy.fix_text(text)
|
||||
ids = {}
|
||||
for key in self.args.jsonl_keys:
|
||||
doc_ids = []
|
||||
text_ids = Encoder.tokenizer.tokenize(text)
|
||||
if len(text_ids) > 0:
|
||||
doc_ids.append(text_ids)
|
||||
if self.args.append_eod:
|
||||
doc_ids[-1].append(Encoder.tokenizer.eod)
|
||||
ids[key] = doc_ids
|
||||
return ids, len(text)
|
||||
|
||||
|
||||
def get_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
group = parser.add_argument_group(title="input data")
|
||||
group.add_argument(
|
||||
"--input",
|
||||
type=str,
|
||||
required=True,
|
||||
help="Path to input jsonl files or lmd archive(s) - if using multiple archives, put them in a comma separated "
|
||||
"list",
|
||||
)
|
||||
group.add_argument(
|
||||
"--jsonl-keys",
|
||||
nargs="+",
|
||||
default=["text"],
|
||||
help="space separate listed of keys to extract from jsonl. Defa",
|
||||
)
|
||||
group.add_argument(
|
||||
"--num-docs",
|
||||
default=None,
|
||||
help="Optional: Number of documents in the input data (if known) for an accurate progress bar.",
|
||||
type=int,
|
||||
)
|
||||
group = parser.add_argument_group(title="tokenizer")
|
||||
group.add_argument(
|
||||
"--tokenizer-type",
|
||||
type=str,
|
||||
required=True,
|
||||
choices=[
|
||||
"HFGPT2Tokenizer",
|
||||
"HFTokenizer",
|
||||
"GPT2BPETokenizer",
|
||||
"CharLevelTokenizer",
|
||||
"TiktokenTokenizer",
|
||||
"RWKVTokenizer",
|
||||
],
|
||||
help="What type of tokenizer to use.",
|
||||
)
|
||||
group.add_argument(
|
||||
"--vocab-file", type=str, default=None, help="Path to the vocab file"
|
||||
)
|
||||
group.add_argument(
|
||||
"--merge-file",
|
||||
type=str,
|
||||
default=None,
|
||||
help="Path to the BPE merge file (if necessary).",
|
||||
)
|
||||
group.add_argument(
|
||||
"--append-eod",
|
||||
action="store_true",
|
||||
help="Append an <eod> token to the end of a document.",
|
||||
)
|
||||
group.add_argument("--ftfy", action="store_true", help="Use ftfy to clean text")
|
||||
group = parser.add_argument_group(title="output data")
|
||||
group.add_argument(
|
||||
"--output-prefix",
|
||||
type=str,
|
||||
required=True,
|
||||
help="Path to binary output file without suffix",
|
||||
)
|
||||
group.add_argument(
|
||||
"--dataset-impl",
|
||||
type=str,
|
||||
default="mmap",
|
||||
choices=["lazy", "cached", "mmap"],
|
||||
help="Dataset implementation to use. Default: mmap",
|
||||
)
|
||||
|
||||
group = parser.add_argument_group(title="runtime")
|
||||
group.add_argument(
|
||||
"--workers", type=int, default=1, help="Number of worker processes to launch"
|
||||
)
|
||||
group.add_argument(
|
||||
"--log-interval",
|
||||
type=int,
|
||||
default=100,
|
||||
help="Interval between progress updates",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
args.keep_empty = False
|
||||
|
||||
# some default/dummy values for the tokenizer
|
||||
args.rank = 0
|
||||
args.make_vocab_size_divisible_by = 128
|
||||
args.model_parallel_size = 1
|
||||
|
||||
return args
|
||||
|
||||
|
||||
def yield_from_files(fnames: list, semaphore):
|
||||
"""
|
||||
Iterator over input documents using lm_dataformat. Should be able to handle jsons / texts /
|
||||
other compressed formats. Also filters out empty documents.
|
||||
|
||||
:param fnames: list of filenames
|
||||
"""
|
||||
|
||||
def yielder(fname, semaphore):
|
||||
for f in filter(lambda x: x, lmd.Reader(fname).stream_data()):
|
||||
semaphore.acquire()
|
||||
yield f
|
||||
|
||||
for fname in fnames:
|
||||
semaphore.acquire()
|
||||
|
||||
yield from yielder(fname, semaphore)
|
||||
|
||||
|
||||
def main():
|
||||
args = get_args()
|
||||
encoder = Encoder(args)
|
||||
tokenizer = build_tokenizer(args)
|
||||
print(f"Vocab size: {tokenizer.vocab_size}")
|
||||
print(f"Output prefix: {args.output_prefix}")
|
||||
|
||||
# build a semaphore object to stop `yield_from_files` from getting ahead of encoder.encode and
|
||||
# hence building up memory
|
||||
semaphore = Semaphore(10000 + args.workers)
|
||||
|
||||
# use multiprocessing to iterate over input documents
|
||||
fin = yield_from_files(args.input.split(","), semaphore)
|
||||
|
||||
if args.workers > 1:
|
||||
pool = multiprocessing.Pool(args.workers, initializer=encoder.initializer)
|
||||
encoded_docs = pool.imap(encoder.encode, fin, chunksize=25)
|
||||
else:
|
||||
encoder.initializer()
|
||||
encoded_docs = (encoder.encode(doc) for doc in fin)
|
||||
|
||||
# make a dataset builder for each key in args.jsonl_keys
|
||||
# each key will output to a different file beginning with args.output_prefix
|
||||
output_bin_files = {}
|
||||
output_idx_files = {}
|
||||
builders = {}
|
||||
for key in args.jsonl_keys:
|
||||
output_bin_files[key] = "{}_{}_{}.bin".format(
|
||||
args.output_prefix, key, "document"
|
||||
)
|
||||
output_idx_files[key] = "{}_{}_{}.idx".format(
|
||||
args.output_prefix, key, "document"
|
||||
)
|
||||
builders[key] = indexed_dataset.make_builder(
|
||||
output_bin_files[key],
|
||||
impl=args.dataset_impl,
|
||||
vocab_size=tokenizer.vocab_size,
|
||||
)
|
||||
|
||||
# actually do tokenization
|
||||
proc_start = time.time()
|
||||
total_bytes_processed = 0
|
||||
pbar = tqdm.tqdm()
|
||||
for i, (doc, bytes_processed) in enumerate(encoded_docs, start=1):
|
||||
total_bytes_processed += bytes_processed
|
||||
|
||||
# release semaphore so `yield_from_files` can add another file to the buffer
|
||||
semaphore.release()
|
||||
|
||||
# add each tokenized document / sentence
|
||||
for key, sentences in doc.items():
|
||||
for sentence in sentences:
|
||||
builders[key].add_item(np.array(sentence, dtype=builders[key].dtype))
|
||||
# separate with eos token
|
||||
builders[key].end_document()
|
||||
|
||||
# log progress
|
||||
if i % args.log_interval == 0:
|
||||
current = time.time()
|
||||
elapsed = current - proc_start
|
||||
mbs = total_bytes_processed / elapsed / 1024 / 1024
|
||||
pbar.set_description(
|
||||
f"Processed {i}{'' if args.num_docs is None else '/' + str(args.num_docs)} documents ({i / elapsed:0.2f} docs/s, {mbs:0.2f} MB/s)."
|
||||
)
|
||||
if i != 0:
|
||||
pbar.update(args.log_interval)
|
||||
|
||||
# save output file
|
||||
for key in args.jsonl_keys:
|
||||
builders[key].finalize(output_idx_files[key])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except Exception as e:
|
||||
with open("error.txt", "w") as f:
|
||||
f.write(str(e))
|
||||
232
finetune/json2binidx_tool/tools/rwkv_tokenizer.py
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
########################################################################################################
|
||||
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
|
||||
# Source: https://github.com/BlinkDL/ChatRWKV/blob/main/tokenizer/rwkv_tokenizer.py
|
||||
########################################################################################################
|
||||
|
||||
import os, sys, time, random
|
||||
|
||||
print('''
|
||||
#######################################################################################################################
|
||||
|
||||
This tokenizer is not used in any RWKV models yet. I plan to use it for the future multilang RWKV models.
|
||||
|
||||
Benefits:
|
||||
|
||||
* Good support of most languages, from European to CJK to Arabic and Hindi and more.
|
||||
|
||||
* Clean vocab. Good for code too. Vocab size = 65525 (use 0 for <|endoftext|>).
|
||||
|
||||
* Good at numbers: the numerical tokens are '0'~'9', '10'~'99', ' 0'~' 9', ' 10'~' 99'.
|
||||
|
||||
* Very easy tokenization:
|
||||
|
||||
** The input text must be in UTF-8.
|
||||
|
||||
** Greedy encoding: always pick the longest (in bytes) token (with the highest id) that matches your UTF-8 bytes.
|
||||
|
||||
* The tokenization result is surprisingly good, because the vocab respects word boundaries and UTF-8 boundaries.
|
||||
|
||||
For 10x faster speed:
|
||||
mypyc rwkv_tokenizer.py
|
||||
python3 -c "import rwkv_tokenizer"
|
||||
|
||||
#######################################################################################################################
|
||||
''')
|
||||
|
||||
########################################################################################################
|
||||
# Tokenizer #1 (reference, naive, slow)
|
||||
########################################################################################################
|
||||
|
||||
class RWKV_TOKENIZER():
|
||||
table = None # : list[list[list[bytes]]] = None
|
||||
good = None # : list[set[int]]
|
||||
wlen = None # : list[int]
|
||||
def __init__(self, file_name):
|
||||
self.vocab_size = 65525
|
||||
self.idx2token = {}
|
||||
sorted = [] # must be already sorted
|
||||
lines = open(file_name, "r", encoding="utf-8").readlines()
|
||||
for l in lines:
|
||||
idx = int(l[:l.index(' ')])
|
||||
x = eval(l[l.index(' '):l.rindex(' ')])
|
||||
x = x.encode("utf-8") if isinstance(x, str) else x
|
||||
assert isinstance(x, bytes)
|
||||
assert len(x) == int(l[l.rindex(' '):])
|
||||
sorted += [x]
|
||||
self.idx2token[idx] = x
|
||||
|
||||
self.token2idx = {}
|
||||
for k, v in self.idx2token.items():
|
||||
self.token2idx[v] = int(k)
|
||||
|
||||
# precompute some tables for fast matching
|
||||
self.table = [[[] for j in range(256)] for i in range(256)]
|
||||
self.good = [set() for i in range(256)]
|
||||
self.wlen = [0 for i in range(256)]
|
||||
|
||||
for i in reversed(range(len(sorted))): # reverse order - match longer tokens first
|
||||
s = sorted[i]
|
||||
if len(s) >= 2:
|
||||
s0 = int(s[0])
|
||||
s1 = int(s[1])
|
||||
self.table[s0][s1] += [s]
|
||||
self.wlen[s0] = max(self.wlen[s0], len(s))
|
||||
self.good[s0].add(s1)
|
||||
|
||||
def encodeBytes(self, src: bytes):
|
||||
src_len: int = len(src)
|
||||
tokens = []
|
||||
i: int = 0
|
||||
while i < src_len:
|
||||
s: bytes = src[i : i + 1]
|
||||
|
||||
if i < src_len - 1:
|
||||
s1: int = int(src[i + 1])
|
||||
s0: int = int(src[i])
|
||||
if s1 in self.good[s0]:
|
||||
sss: bytes = src[i : i + self.wlen[s0]]
|
||||
try:
|
||||
s = next(filter(sss.startswith, self.table[s0][s1]))
|
||||
except:
|
||||
pass
|
||||
tokens.append(self.token2idx[s])
|
||||
i += len(s)
|
||||
|
||||
return tokens
|
||||
|
||||
def decodeBytes(self, tokens):
|
||||
return b''.join(map(lambda i: self.idx2token[i], tokens))
|
||||
|
||||
def encode(self, src: str):
|
||||
return self.encodeBytes(src.encode("utf-8"))
|
||||
|
||||
def decode(self, tokens):
|
||||
return self.decodeBytes(tokens).decode('utf-8')
|
||||
|
||||
def token_to_id(self, token):
|
||||
return self.token2idx[token]
|
||||
|
||||
def get_vocab_size(self):
|
||||
return self.vocab_size
|
||||
|
||||
def get_vocab(self):
|
||||
return self.idx2token
|
||||
|
||||
def printTokens(self, tokens):
|
||||
for i in tokens:
|
||||
s = self.idx2token[i]
|
||||
try:
|
||||
s = s.decode('utf-8')
|
||||
except:
|
||||
pass
|
||||
print(f'{repr(s)}{i}', end=' ')
|
||||
# print(repr(s), i)
|
||||
print()
|
||||
|
||||
########################################################################################################
|
||||
# Tokenizer #2 (trie, faster) https://github.com/TkskKurumi/ChatRWKV-TRIE-Tokenizer
|
||||
########################################################################################################
|
||||
|
||||
class TRIE:
|
||||
__slots__ = tuple("ch,to,values,front".split(","))
|
||||
to:list
|
||||
values:set
|
||||
def __init__(self, front=None, ch=None):
|
||||
self.ch = ch
|
||||
self.to = [None for ch in range(256)]
|
||||
self.values = set()
|
||||
self.front = front
|
||||
|
||||
def __repr__(self):
|
||||
fr = self
|
||||
ret = []
|
||||
while(fr!=None):
|
||||
if(fr.ch!=None):
|
||||
ret.append(fr.ch)
|
||||
fr = fr.front
|
||||
return "<TRIE %s %s>"%(ret[::-1], self.values)
|
||||
|
||||
def add(self, key:bytes, idx:int=0, val=None):
|
||||
if(idx == len(key)):
|
||||
if(val is None):
|
||||
val = key
|
||||
self.values.add(val)
|
||||
return self
|
||||
ch = key[idx]
|
||||
if(self.to[ch] is None):
|
||||
self.to[ch] = TRIE(front=self, ch=ch)
|
||||
return self.to[ch].add(key, idx=idx+1, val=val)
|
||||
|
||||
def find_longest(self, key:bytes, idx:int=0):
|
||||
u:TRIE = self
|
||||
ch:int = key[idx]
|
||||
|
||||
while(u.to[ch] is not None):
|
||||
u = u.to[ch]
|
||||
idx += 1
|
||||
if(u.values):
|
||||
ret = idx, u, u.values
|
||||
if(idx==len(key)):
|
||||
break
|
||||
ch = key[idx]
|
||||
return ret
|
||||
|
||||
class TRIE_TOKENIZER():
|
||||
def __init__(self, file_name):
|
||||
self.vocab_size = 65525
|
||||
self.idx2token = {}
|
||||
sorted = [] # must be already sorted
|
||||
with open(file_name, "r", encoding="utf-8") as f:
|
||||
lines = f.readlines()
|
||||
for l in lines:
|
||||
idx = int(l[:l.index(' ')])
|
||||
x = eval(l[l.index(' '):l.rindex(' ')])
|
||||
x = x.encode("utf-8") if isinstance(x, str) else x
|
||||
assert isinstance(x, bytes)
|
||||
assert len(x) == int(l[l.rindex(' '):])
|
||||
sorted += [x]
|
||||
self.idx2token[idx] = x
|
||||
|
||||
self.token2idx = {}
|
||||
for k,v in self.idx2token.items():
|
||||
self.token2idx[v] = int(k)
|
||||
|
||||
self.root = TRIE()
|
||||
for t, i in self.token2idx.items():
|
||||
_ = self.root.add(t, val=(t, i))
|
||||
|
||||
def encodeBytes(self, src:bytes):
|
||||
idx:int = 0
|
||||
tokens = []
|
||||
while (idx < len(src)):
|
||||
_idx:int = idx
|
||||
idx, _, values = self.root.find_longest(src, idx)
|
||||
assert(idx != _idx)
|
||||
_, token = next(iter(values))
|
||||
tokens.append(token)
|
||||
return tokens
|
||||
|
||||
def decodeBytes(self, tokens):
|
||||
return b''.join(map(lambda i: self.idx2token[i], tokens))
|
||||
|
||||
def encode(self, src):
|
||||
return self.encodeBytes(src.encode("utf-8"))
|
||||
|
||||
def decode(self, tokens):
|
||||
return self.decodeBytes(tokens).decode('utf-8')
|
||||
|
||||
def get_vocab_size(self):
|
||||
return self.vocab_size
|
||||
|
||||
def get_vocab(self):
|
||||
return self.idx2token
|
||||
|
||||
def printTokens(self, tokens):
|
||||
for i in tokens:
|
||||
s = self.idx2token[i]
|
||||
try:
|
||||
s = s.decode('utf-8')
|
||||
except:
|
||||
pass
|
||||
print(f'{repr(s)}{i}', end=' ')
|
||||
print()
|
||||
205
finetune/json2binidx_tool/tools/tokenizer.py
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
# Copyright (c) 2021, EleutherAI
|
||||
# This file is based on code by the authors denoted below and has been modified from its original version.
|
||||
#
|
||||
# Copyright (c) 2020, NVIDIA CORPORATION. All rights reserved.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
"""Megatron tokenizers."""
|
||||
|
||||
from abc import ABC
|
||||
from abc import abstractmethod
|
||||
|
||||
from tokenizers import Tokenizer
|
||||
from rwkv_tokenizer import RWKV_TOKENIZER, TRIE_TOKENIZER
|
||||
|
||||
from typing import List, Union
|
||||
|
||||
|
||||
def build_tokenizer(args):
|
||||
"""Initialize tokenizer."""
|
||||
if args.rank == 0:
|
||||
print("> building {} tokenizer ...".format(args.tokenizer_type), flush=True)
|
||||
|
||||
# Select and instantiate the tokenizer.
|
||||
|
||||
if args.tokenizer_type.lower() == "HFTokenizer".lower():
|
||||
assert args.vocab_file is not None
|
||||
tokenizer = HFTokenizer(args.vocab_file)
|
||||
elif args.tokenizer_type.lower() == "RWKVTokenizer".lower():
|
||||
assert args.vocab_file is not None
|
||||
tokenizer = RWKVTokenizer(args.vocab_file)
|
||||
else:
|
||||
raise NotImplementedError(
|
||||
"{} tokenizer is not " "implemented.".format(args.tokenizer_type)
|
||||
)
|
||||
|
||||
# Add vocab size.
|
||||
args.padded_vocab_size = _vocab_size_with_padding(tokenizer.vocab_size, args)
|
||||
|
||||
return tokenizer
|
||||
|
||||
|
||||
def _vocab_size_with_padding(orig_vocab_size, args):
|
||||
"""Pad vocab size so it is divisible by model parallel size and
|
||||
still having GPU friendly size."""
|
||||
|
||||
after = orig_vocab_size
|
||||
multiple = args.make_vocab_size_divisible_by * args.model_parallel_size
|
||||
while (after % multiple) != 0:
|
||||
after += 1
|
||||
if args.rank == 0:
|
||||
print(
|
||||
" > padded vocab (size: {}) with {} dummy tokens "
|
||||
"(new size: {})".format(orig_vocab_size, after - orig_vocab_size, after),
|
||||
flush=True,
|
||||
)
|
||||
return after
|
||||
|
||||
|
||||
class AbstractTokenizer(ABC):
|
||||
"""Abstract class for tokenizer."""
|
||||
|
||||
def __init__(self, name):
|
||||
self.name = name
|
||||
super().__init__()
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def vocab_size(self):
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def vocab(self):
|
||||
"""Dictionary from vocab text token to id token."""
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def inv_vocab(self):
|
||||
"""Dictionary from vocab id token to text token."""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def tokenize(self, text):
|
||||
pass
|
||||
|
||||
def detokenize(self, token_ids):
|
||||
raise NotImplementedError(
|
||||
"detokenizer is not implemented for {} " "tokenizer".format(self.name)
|
||||
)
|
||||
|
||||
@property
|
||||
def cls(self):
|
||||
raise NotImplementedError(
|
||||
"CLS is not provided for {} " "tokenizer".format(self.name)
|
||||
)
|
||||
|
||||
@property
|
||||
def sep(self):
|
||||
raise NotImplementedError(
|
||||
"SEP is not provided for {} " "tokenizer".format(self.name)
|
||||
)
|
||||
|
||||
@property
|
||||
def pad(self):
|
||||
raise NotImplementedError(
|
||||
"PAD is not provided for {} " "tokenizer".format(self.name)
|
||||
)
|
||||
|
||||
@property
|
||||
def eod(self):
|
||||
raise NotImplementedError(
|
||||
"EOD is not provided for {} " "tokenizer".format(self.name)
|
||||
)
|
||||
|
||||
@property
|
||||
def mask(self):
|
||||
raise NotImplementedError(
|
||||
"MASK is not provided for {} " "tokenizer".format(self.name)
|
||||
)
|
||||
|
||||
|
||||
class HFTokenizer(AbstractTokenizer):
|
||||
"""Designed to Integrate HF's Tokenizer library."""
|
||||
|
||||
def __init__(self, vocab_file):
|
||||
name = "HFTokenizer"
|
||||
super().__init__(name)
|
||||
|
||||
self.tokenizer = Tokenizer.from_file(vocab_file)
|
||||
self.eod_id = self.tokenizer.token_to_id("<|endoftext|>")
|
||||
self.pad_id = self.tokenizer.token_to_id("<|padding|>")
|
||||
|
||||
@property
|
||||
def vocab_size(self):
|
||||
return self.tokenizer.get_vocab_size()
|
||||
|
||||
@property
|
||||
def vocab(self):
|
||||
return self.tokenizer.get_vocab()
|
||||
|
||||
@property
|
||||
def inv_vocab(self):
|
||||
return self.tokenizer.decoder
|
||||
|
||||
def tokenize(self, text: str):
|
||||
return self.tokenizer.encode(text).ids
|
||||
|
||||
def tokenize_batch(self, text_batch: Union[List[str], str]):
|
||||
return self.tokenizer.encode_batch(text_batch)
|
||||
|
||||
def detokenize(self, token_ids):
|
||||
return self.tokenizer.decode(token_ids)
|
||||
|
||||
@property
|
||||
def eod(self):
|
||||
return self.eod_id
|
||||
|
||||
|
||||
class RWKVTokenizer(AbstractTokenizer):
|
||||
"""RWKV Worlds Tokenizer."""
|
||||
|
||||
def __init__(self, vocab_file='rwkv_vocab_v20230424.txt'):
|
||||
name = "RWKVTokenizer"
|
||||
super().__init__(name)
|
||||
|
||||
self.tokenizer = TRIE_TOKENIZER(vocab_file)
|
||||
self.eod_id = 0 # self.tokenizer.token_to_id("<|endoftext|>")
|
||||
# self.pad_id = self.tokenizer.token_to_id("<|padding|>")
|
||||
|
||||
@property
|
||||
def vocab_size(self):
|
||||
return self.tokenizer.get_vocab_size()
|
||||
|
||||
@property
|
||||
def vocab(self):
|
||||
return self.tokenizer.get_vocab()
|
||||
|
||||
@property
|
||||
def inv_vocab(self):
|
||||
return self.tokenizer.decode
|
||||
|
||||
def tokenize(self, text: str):
|
||||
return self.tokenizer.encode(text)
|
||||
|
||||
def tokenize_batch(self, text_batch: Union[List[str], str]):
|
||||
return self.tokenizer.encode_batch(text_batch)
|
||||
|
||||
def detokenize(self, token_ids):
|
||||
return self.tokenizer.decode(token_ids)
|
||||
|
||||
@property
|
||||
def eod(self):
|
||||
return self.eod_id
|
||||
133
finetune/lora/cuda/wkv_cuda.cu
vendored
Normal file
@@ -0,0 +1,133 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#define MIN_VALUE (-1e38)
|
||||
|
||||
template <typename F>
|
||||
__global__ void kernel_forward(const int B, const int T, const int C,
|
||||
const F *__restrict__ const _w, const F *__restrict__ const _u, const F *__restrict__ const _k, const F *__restrict__ const _v,
|
||||
F *__restrict__ const _y) {
|
||||
const int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
const int _b = idx / C;
|
||||
const int _c = idx % C;
|
||||
const int _offset = _b * T * C + _c;
|
||||
|
||||
F u = _u[_c];
|
||||
F w = _w[_c];
|
||||
const F *__restrict__ const k = _k + _offset;
|
||||
const F *__restrict__ const v = _v + _offset;
|
||||
F *__restrict__ const y = _y + _offset;
|
||||
|
||||
// aa and bb are running sums divided by exp(pp) (to avoid overflow)
|
||||
F aa = 0, bb = 0, pp = MIN_VALUE;
|
||||
for (int i = 0; i < T; i++) {
|
||||
const int ii = i * C;
|
||||
const F kk = k[ii];
|
||||
const F vv = v[ii];
|
||||
|
||||
F ww = u + kk;
|
||||
F p = max(pp, ww);
|
||||
F e1 = exp(pp - p);
|
||||
F e2 = exp(ww - p);
|
||||
y[ii] = (e1 * aa + e2 * vv) / (e1 * bb + e2);
|
||||
|
||||
ww = w + pp;
|
||||
p = max(ww, kk);
|
||||
e1 = exp(ww - p);
|
||||
e2 = exp(kk - p);
|
||||
aa = e1 * aa + e2 * vv;
|
||||
bb = e1 * bb + e2;
|
||||
pp = p;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename F>
|
||||
__global__ void kernel_backward(const int B, const int T, const int C,
|
||||
const F *__restrict__ const _w, const F *__restrict__ const _u, const F *__restrict__ const _k, const F *__restrict__ const _v,
|
||||
const F *__restrict__ const _y, const F *__restrict__ const _gy,
|
||||
F *__restrict__ const _gw, F *__restrict__ const _gu, F *__restrict__ const _gk, F *__restrict__ const _gv) {
|
||||
const int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
const int _b = idx / C;
|
||||
const int _c = idx % C;
|
||||
const int _offset = _b * T * C + _c;
|
||||
|
||||
F u = _u[_c];
|
||||
F w = _w[_c];
|
||||
const F *__restrict__ const k = _k + _offset;
|
||||
const F *__restrict__ const v = _v + _offset;
|
||||
const F *__restrict__ const y = _y + _offset;
|
||||
const F *__restrict__ const gy = _gy + _offset;
|
||||
F *__restrict__ const gk = _gk + _offset;
|
||||
F *__restrict__ const gv = _gv + _offset;
|
||||
|
||||
F q[Tmax], r[Tmax];
|
||||
|
||||
F gw = 0, gu = 0, aa = 0, bb = 0, ga = 0, gb = 0, pp = MIN_VALUE;
|
||||
for (int i = 0; i < T; i++) {
|
||||
const int ii = i * C;
|
||||
const F kk = k[ii];
|
||||
const F vv = v[ii];
|
||||
const F yy = y[ii];
|
||||
|
||||
F ww = u + kk;
|
||||
F p = max(pp, ww);
|
||||
F e1 = exp(pp - p);
|
||||
F e2 = exp(ww - p);
|
||||
const F qq = gy[ii] / (e1 * bb + e2);
|
||||
gw += (ga - gb * yy) * e1 * qq;
|
||||
gu += (vv - yy) * e2 * qq;
|
||||
q[i] = qq;
|
||||
r[i] = ww - p;
|
||||
|
||||
ww = w + pp;
|
||||
p = max(ww, kk);
|
||||
e1 = exp(ww - p);
|
||||
e2 = exp(kk - p);
|
||||
ga = e1 * (aa + ga);
|
||||
gb = e1 * (bb + gb);
|
||||
aa = e1 * aa + e2 * vv;
|
||||
bb = e1 * bb + e2;
|
||||
pp = p;
|
||||
}
|
||||
const int _offsetBC = _b * C + _c;
|
||||
_gw[_offsetBC] = gw * _w[_c]; // multiply by w because of w -> -exp(w) in python forward()
|
||||
_gu[_offsetBC] = gu;
|
||||
|
||||
aa = 0, bb = 0, pp = MIN_VALUE;
|
||||
for (int i = T - 1; i >= 0; i--) {
|
||||
const int ii = i * C;
|
||||
const F kk = k[ii];
|
||||
const F vv = v[ii];
|
||||
const F yy = y[ii];
|
||||
const F qq = q[i];
|
||||
const F rr = r[i];
|
||||
|
||||
F e1 = qq * exp(rr);
|
||||
F e2 = exp(kk + pp);
|
||||
gk[ii] = e1 * (vv - yy) + e2 * (aa * vv + bb);
|
||||
gv[ii] = e1 + e2 * aa;
|
||||
|
||||
const F ww = w + pp;
|
||||
const F www = rr - u - kk;
|
||||
const F p = max(ww, www);
|
||||
e1 = exp(ww - p);
|
||||
e2 = qq * exp(www - p);
|
||||
aa = e1 * aa + e2;
|
||||
bb = e1 * bb - e2 * yy;
|
||||
pp = p;
|
||||
}
|
||||
}
|
||||
|
||||
void cuda_forward(int B, int T, int C, float *w, float *u, float *k, float *v, float *y) {
|
||||
dim3 threadsPerBlock( min(C, 32) ); // requires --maxrregcount 60 for optimal performance
|
||||
assert(B * C % threadsPerBlock.x == 0);
|
||||
dim3 numBlocks(B * C / threadsPerBlock.x);
|
||||
kernel_forward<<<numBlocks, threadsPerBlock>>>(B, T, C, w, u, k, v, y);
|
||||
}
|
||||
|
||||
void cuda_backward(int B, int T, int C, float *w, float *u, float *k, float *v, float *y, float *gy, float *gw, float *gu, float *gk, float *gv) {
|
||||
dim3 threadsPerBlock( min(C, 32) ); // requires --maxrregcount 60 for optimal performance
|
||||
assert(B * C % threadsPerBlock.x == 0);
|
||||
dim3 numBlocks(B * C / threadsPerBlock.x);
|
||||
kernel_backward<<<numBlocks, threadsPerBlock>>>(B, T, C, w, u, k, v, y, gy, gw, gu, gk, gv);
|
||||
}
|
||||
132
finetune/lora/cuda/wkv_cuda_bf16.cu
vendored
Normal file
@@ -0,0 +1,132 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include "ATen/ATen.h"
|
||||
#define MIN_VALUE (-1e38)
|
||||
typedef at::BFloat16 bf16;
|
||||
|
||||
__global__ void kernel_forward(const int B, const int T, const int C,
|
||||
const float *__restrict__ const _w, const bf16 *__restrict__ const _u, const bf16 *__restrict__ const _k, const bf16 *__restrict__ const _v,
|
||||
bf16 *__restrict__ const _y) {
|
||||
const int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
const int _b = idx / C;
|
||||
const int _c = idx % C;
|
||||
const int _offset = _b * T * C + _c;
|
||||
|
||||
float u = float(_u[_c]);
|
||||
float w = _w[_c];
|
||||
const bf16 *__restrict__ const k = _k + _offset;
|
||||
const bf16 *__restrict__ const v = _v + _offset;
|
||||
bf16 *__restrict__ const y = _y + _offset;
|
||||
|
||||
// aa and bb are running sums divided by exp(pp) (to avoid overflow)
|
||||
float aa = 0, bb = 0, pp = MIN_VALUE;
|
||||
for (int i = 0; i < T; i++) {
|
||||
const int ii = i * C;
|
||||
const float kk = float(k[ii]);
|
||||
const float vv = float(v[ii]);
|
||||
|
||||
float ww = u + kk;
|
||||
float p = max(pp, ww);
|
||||
float e1 = exp(pp - p);
|
||||
float e2 = exp(ww - p);
|
||||
y[ii] = bf16((e1 * aa + e2 * vv) / (e1 * bb + e2));
|
||||
|
||||
ww = w + pp;
|
||||
p = max(ww, kk);
|
||||
e1 = exp(ww - p);
|
||||
e2 = exp(kk - p);
|
||||
aa = e1 * aa + e2 * vv;
|
||||
bb = e1 * bb + e2;
|
||||
pp = p;
|
||||
}
|
||||
}
|
||||
|
||||
__global__ void kernel_backward(const int B, const int T, const int C,
|
||||
const float *__restrict__ const _w, const bf16 *__restrict__ const _u, const bf16 *__restrict__ const _k, const bf16 *__restrict__ const _v,
|
||||
const bf16 *__restrict__ const _y, const bf16 *__restrict__ const _gy,
|
||||
bf16 *__restrict__ const _gw, bf16 *__restrict__ const _gu, bf16 *__restrict__ const _gk, bf16 *__restrict__ const _gv) {
|
||||
const int idx = blockIdx.x * blockDim.x + threadIdx.x;
|
||||
const int _b = idx / C;
|
||||
const int _c = idx % C;
|
||||
const int _offset = _b * T * C + _c;
|
||||
|
||||
float u = float(_u[_c]);
|
||||
float w = _w[_c];
|
||||
const bf16 *__restrict__ const k = _k + _offset;
|
||||
const bf16 *__restrict__ const v = _v + _offset;
|
||||
const bf16 *__restrict__ const y = _y + _offset;
|
||||
const bf16 *__restrict__ const gy = _gy + _offset;
|
||||
bf16 *__restrict__ const gk = _gk + _offset;
|
||||
bf16 *__restrict__ const gv = _gv + _offset;
|
||||
|
||||
float q[Tmax], r[Tmax];
|
||||
|
||||
float gw = 0, gu = 0, aa = 0, bb = 0, ga = 0, gb = 0, pp = MIN_VALUE;
|
||||
for (int i = 0; i < T; i++) {
|
||||
const int ii = i * C;
|
||||
const float kk = float(k[ii]);
|
||||
const float vv = float(v[ii]);
|
||||
const float yy = float(y[ii]);
|
||||
|
||||
float ww = u + kk;
|
||||
float p = max(pp, ww);
|
||||
float e1 = exp(pp - p);
|
||||
float e2 = exp(ww - p);
|
||||
const float qq = float(gy[ii]) / (e1 * bb + e2);
|
||||
gw += (ga - gb * yy) * e1 * qq;
|
||||
gu += (vv - yy) * e2 * qq;
|
||||
q[i] = qq;
|
||||
r[i] = ww - p;
|
||||
|
||||
ww = w + pp;
|
||||
p = max(ww, kk);
|
||||
e1 = exp(ww - p);
|
||||
e2 = exp(kk - p);
|
||||
ga = e1 * (aa + ga);
|
||||
gb = e1 * (bb + gb);
|
||||
aa = e1 * aa + e2 * vv;
|
||||
bb = e1 * bb + e2;
|
||||
pp = p;
|
||||
}
|
||||
const int _offsetBC = _b * C + _c;
|
||||
_gw[_offsetBC] = bf16(gw * _w[_c]); // multiply by w because of w -> -exp(w) in python forward()
|
||||
_gu[_offsetBC] = bf16(gu);
|
||||
|
||||
aa = 0, bb = 0, pp = MIN_VALUE;
|
||||
for (int i = T - 1; i >= 0; i--) {
|
||||
const int ii = i * C;
|
||||
const float kk = float(k[ii]);
|
||||
const float vv = float(v[ii]);
|
||||
const float yy = float(y[ii]);
|
||||
const float qq = q[i];
|
||||
const float rr = r[i];
|
||||
|
||||
float e1 = qq * exp(rr);
|
||||
float e2 = exp(kk + pp);
|
||||
gk[ii] = bf16(e1 * (vv - yy) + e2 * (aa * vv + bb));
|
||||
gv[ii] = bf16(e1 + e2 * aa);
|
||||
|
||||
const float ww = w + pp;
|
||||
const float www = rr - u - kk;
|
||||
const float p = max(ww, www);
|
||||
e1 = exp(ww - p);
|
||||
e2 = qq * exp(www - p);
|
||||
aa = e1 * aa + e2;
|
||||
bb = e1 * bb - e2 * yy;
|
||||
pp = p;
|
||||
}
|
||||
}
|
||||
|
||||
void cuda_forward(int B, int T, int C, float *w, bf16 *u, bf16 *k, bf16 *v, bf16 *y) {
|
||||
dim3 threadsPerBlock( min(C, 32) ); // requires --maxrregcount 60 for optimal performance
|
||||
assert(B * C % threadsPerBlock.x == 0);
|
||||
dim3 numBlocks(B * C / threadsPerBlock.x);
|
||||
kernel_forward<<<numBlocks, threadsPerBlock>>>(B, T, C, w, u, k, v, y);
|
||||
}
|
||||
|
||||
void cuda_backward(int B, int T, int C, float *w, bf16 *u, bf16 *k, bf16 *v, bf16 *y, bf16 *gy, bf16 *gw, bf16 *gu, bf16 *gk, bf16 *gv) {
|
||||
dim3 threadsPerBlock( min(C, 32) ); // requires --maxrregcount 60 for optimal performance
|
||||
assert(B * C % threadsPerBlock.x == 0);
|
||||
dim3 numBlocks(B * C / threadsPerBlock.x);
|
||||
kernel_backward<<<numBlocks, threadsPerBlock>>>(B, T, C, w, u, k, v, y, gy, gw, gu, gk, gv);
|
||||
}
|
||||
21
finetune/lora/cuda/wkv_op.cpp
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
#include <torch/extension.h>
|
||||
|
||||
void cuda_forward(int B, int T, int C, float *w, float *u, float *k, float *v, float *y);
|
||||
void cuda_backward(int B, int T, int C, float *w, float *u, float *k, float *v, float *y, float *gy, float *gw, float *gu, float *gk, float *gv);
|
||||
|
||||
void forward(int64_t B, int64_t T, int64_t C, torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y) {
|
||||
cuda_forward(B, T, C, w.data_ptr<float>(), u.data_ptr<float>(), k.data_ptr<float>(), v.data_ptr<float>(), y.data_ptr<float>());
|
||||
}
|
||||
void backward(int64_t B, int64_t T, int64_t C, torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y, torch::Tensor &gy, torch::Tensor &gw, torch::Tensor &gu, torch::Tensor &gk, torch::Tensor &gv) {
|
||||
cuda_backward(B, T, C, w.data_ptr<float>(), u.data_ptr<float>(), k.data_ptr<float>(), v.data_ptr<float>(), y.data_ptr<float>(), gy.data_ptr<float>(), gw.data_ptr<float>(), gu.data_ptr<float>(), gk.data_ptr<float>(), gv.data_ptr<float>());
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
|
||||
m.def("forward", &forward, "wkv forward");
|
||||
m.def("backward", &backward, "wkv backward");
|
||||
}
|
||||
|
||||
TORCH_LIBRARY(wkv, m) {
|
||||
m.def("forward", forward);
|
||||
m.def("backward", backward);
|
||||
}
|
||||
25
finetune/lora/cuda/wkv_op_bf16.cpp
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
#include <torch/extension.h>
|
||||
#include "ATen/ATen.h"
|
||||
typedef at::BFloat16 bf16;
|
||||
|
||||
void cuda_forward(int B, int T, int C, float *w, bf16 *u, bf16 *k, bf16 *v, bf16 *y);
|
||||
void cuda_backward(int B, int T, int C, float *w, bf16 *u, bf16 *k, bf16 *v, bf16 *y, bf16 *gy, bf16 *gw, bf16 *gu, bf16 *gk, bf16 *gv);
|
||||
|
||||
void forward(int64_t B, int64_t T, int64_t C, torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y) {
|
||||
cuda_forward(B, T, C, w.data_ptr<float>(), u.data_ptr<bf16>(), k.data_ptr<bf16>(), v.data_ptr<bf16>(), y.data_ptr<bf16>());
|
||||
}
|
||||
void backward(int64_t B, int64_t T, int64_t C, torch::Tensor &w, torch::Tensor &u, torch::Tensor &k, torch::Tensor &v, torch::Tensor &y,
|
||||
torch::Tensor &gy, torch::Tensor &gw, torch::Tensor &gu, torch::Tensor &gk, torch::Tensor &gv) {
|
||||
cuda_backward(B, T, C, w.data_ptr<float>(), u.data_ptr<bf16>(), k.data_ptr<bf16>(), v.data_ptr<bf16>(), y.data_ptr<bf16>(),
|
||||
gy.data_ptr<bf16>(), gw.data_ptr<bf16>(), gu.data_ptr<bf16>(), gk.data_ptr<bf16>(), gv.data_ptr<bf16>());
|
||||
}
|
||||
|
||||
PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
|
||||
m.def("forward", &forward, "wkv forward");
|
||||
m.def("backward", &backward, "wkv backward");
|
||||
}
|
||||
|
||||
TORCH_LIBRARY(wkv, m) {
|
||||
m.def("forward", forward);
|
||||
m.def("backward", backward);
|
||||
}
|
||||
68
finetune/lora/merge_lora.py
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
from collections import OrderedDict
|
||||
import os
|
||||
import sys
|
||||
from typing import Dict
|
||||
import typing
|
||||
import torch
|
||||
|
||||
try:
|
||||
if "-h" in sys.argv or "--help" in sys.argv:
|
||||
print(
|
||||
f"Usage: python3 {sys.argv[0]} [--use-gpu] <lora_alpha> <base_model.pth> <lora_checkpoint.pth> <output.pth>"
|
||||
)
|
||||
|
||||
if sys.argv[1] == "--use-gpu":
|
||||
device = "cuda"
|
||||
lora_alpha, base_model, lora, output = (
|
||||
float(sys.argv[2]),
|
||||
sys.argv[3],
|
||||
sys.argv[4],
|
||||
sys.argv[5],
|
||||
)
|
||||
else:
|
||||
device = "cpu"
|
||||
lora_alpha, base_model, lora, output = (
|
||||
float(sys.argv[1]),
|
||||
sys.argv[2],
|
||||
sys.argv[3],
|
||||
sys.argv[4],
|
||||
)
|
||||
|
||||
with torch.no_grad():
|
||||
w: Dict[str, torch.Tensor] = torch.load(base_model, map_location="cpu")
|
||||
# merge LoRA-only slim checkpoint into the main weights
|
||||
w_lora: Dict[str, torch.Tensor] = torch.load(lora, map_location="cpu")
|
||||
for k in w_lora.keys():
|
||||
w[k] = w_lora[k]
|
||||
output_w: typing.OrderedDict[str, torch.Tensor] = OrderedDict()
|
||||
# merge LoRA weights
|
||||
keys = list(w.keys())
|
||||
for k in keys:
|
||||
if k.endswith(".weight"):
|
||||
prefix = k[: -len(".weight")]
|
||||
lora_A = prefix + ".lora_A"
|
||||
lora_B = prefix + ".lora_B"
|
||||
if lora_A in keys:
|
||||
assert lora_B in keys
|
||||
print(f"merging {lora_A} and {lora_B} into {k}")
|
||||
assert w[lora_B].shape[1] == w[lora_A].shape[0]
|
||||
lora_r = w[lora_B].shape[1]
|
||||
w[k] = w[k].to(device=device)
|
||||
w[lora_A] = w[lora_A].to(device=device)
|
||||
w[lora_B] = w[lora_B].to(device=device)
|
||||
w[k] += w[lora_B] @ w[lora_A] * (lora_alpha / lora_r)
|
||||
output_w[k] = w[k].to(device="cpu", copy=True)
|
||||
del w[k]
|
||||
del w[lora_A]
|
||||
del w[lora_B]
|
||||
continue
|
||||
|
||||
if "lora" not in k:
|
||||
print(f"retaining {k}")
|
||||
output_w[k] = w[k].clone()
|
||||
del w[k]
|
||||
|
||||
torch.save(output_w, output)
|
||||
except Exception as e:
|
||||
with open("error.txt", "w") as f:
|
||||
f.write(str(e))
|
||||
0
finetune/lora/src/__init__.py
vendored
Normal file
269
finetune/lora/src/binidx.py
vendored
Normal file
@@ -0,0 +1,269 @@
|
||||
from lib2to3.pgen2 import token
|
||||
import os
|
||||
import torch
|
||||
import numpy as np
|
||||
import shutil
|
||||
import struct
|
||||
from functools import lru_cache
|
||||
from itertools import accumulate
|
||||
|
||||
def print_rank_0(*message):
|
||||
pass
|
||||
# """If distributed is initialized print only on rank 0."""
|
||||
# if torch.distributed.is_initialized():
|
||||
# if torch.distributed.get_rank() == 0:
|
||||
# print(*message, flush=True)
|
||||
# else:
|
||||
# print(*message, flush=True)
|
||||
|
||||
def _warmup_mmap_file(path):
|
||||
pass
|
||||
# with open(path, "rb") as stream:
|
||||
# while stream.read(100 * 1024 * 1024):
|
||||
# pass
|
||||
|
||||
dtypes = {
|
||||
1: np.uint8,
|
||||
2: np.int8,
|
||||
3: np.int16,
|
||||
4: np.int32,
|
||||
5: np.int64,
|
||||
6: float,
|
||||
7: np.double,
|
||||
8: np.uint16,
|
||||
}
|
||||
|
||||
def code(dtype):
|
||||
for k in dtypes.keys():
|
||||
if dtypes[k] == dtype:
|
||||
return k
|
||||
raise ValueError(dtype)
|
||||
|
||||
def index_file_path(prefix_path):
|
||||
return prefix_path + ".idx"
|
||||
|
||||
def data_file_path(prefix_path):
|
||||
return prefix_path + ".bin"
|
||||
|
||||
class MMapIndexedDataset(torch.utils.data.Dataset):
|
||||
class Index(object):
|
||||
_HDR_MAGIC = b"MMIDIDX\x00\x00"
|
||||
|
||||
@classmethod
|
||||
def writer(cls, path, dtype):
|
||||
class _Writer(object):
|
||||
def __enter__(self):
|
||||
self._file = open(path, "wb")
|
||||
|
||||
# Write Magic string so we can check the file format then opening it again.
|
||||
self._file.write(cls._HDR_MAGIC)
|
||||
# Write version number
|
||||
# Little endian unsigned 64 Bit integer
|
||||
self._file.write(struct.pack("<Q", 1))
|
||||
# Little endian unsigned 8 Bit integer
|
||||
self._file.write(struct.pack("<B", code(dtype)))
|
||||
|
||||
return self
|
||||
|
||||
@staticmethod
|
||||
def _get_pointers(sizes):
|
||||
dtype_size = dtype().itemsize
|
||||
address = 0
|
||||
pointers = []
|
||||
|
||||
for size in sizes:
|
||||
pointers.append(address)
|
||||
address += size * dtype_size
|
||||
|
||||
return pointers
|
||||
|
||||
def write(self, sizes, doc_idx):
|
||||
pointers = self._get_pointers(sizes)
|
||||
|
||||
# Little endian unsigned 64 Bit integer
|
||||
self._file.write(struct.pack("<Q", len(sizes)))
|
||||
# Little endian unsigned 64 Bit integer
|
||||
self._file.write(struct.pack("<Q", len(doc_idx)))
|
||||
|
||||
sizes = np.array(sizes, dtype=np.int32)
|
||||
self._file.write(sizes.tobytes(order="C"))
|
||||
del sizes
|
||||
|
||||
pointers = np.array(pointers, dtype=np.int64)
|
||||
self._file.write(pointers.tobytes(order="C"))
|
||||
del pointers
|
||||
|
||||
doc_idx = np.array(doc_idx, dtype=np.int64)
|
||||
self._file.write(doc_idx.tobytes(order="C"))
|
||||
|
||||
def __exit__(self, exc_type, exc_val, exc_tb):
|
||||
self._file.close()
|
||||
|
||||
return _Writer()
|
||||
|
||||
def __init__(self, path, skip_warmup=False):
|
||||
with open(path, "rb") as stream:
|
||||
magic_test = stream.read(9)
|
||||
assert self._HDR_MAGIC == magic_test, (
|
||||
"Index file doesn't match expected format. "
|
||||
"Make sure that --dataset-impl is configured properly."
|
||||
)
|
||||
# Little endian unsigned 64 Bit integer
|
||||
version = struct.unpack("<Q", stream.read(8))
|
||||
assert (1,) == version
|
||||
|
||||
# Little endian unsigned 8 Bit integer
|
||||
(dtype_code,) = struct.unpack("<B", stream.read(1))
|
||||
self._dtype = dtypes[dtype_code]
|
||||
self._dtype_size = self._dtype().itemsize
|
||||
|
||||
self._len = struct.unpack("<Q", stream.read(8))[0]
|
||||
self._doc_count = struct.unpack("<Q", stream.read(8))[0]
|
||||
offset = stream.tell()
|
||||
|
||||
if not skip_warmup:
|
||||
print_rank_0(" warming up index mmap file...")
|
||||
_warmup_mmap_file(path)
|
||||
|
||||
self._bin_buffer_mmap = np.memmap(path, mode="r", order="C")
|
||||
self._bin_buffer = memoryview(self._bin_buffer_mmap)
|
||||
print_rank_0(" reading sizes...")
|
||||
self._sizes = np.frombuffer(
|
||||
self._bin_buffer, dtype=np.int32, count=self._len, offset=offset
|
||||
)
|
||||
print_rank_0(" reading pointers...")
|
||||
self._pointers = np.frombuffer(
|
||||
self._bin_buffer,
|
||||
dtype=np.int64,
|
||||
count=self._len,
|
||||
offset=offset + self._sizes.nbytes,
|
||||
)
|
||||
print_rank_0(" reading document index...")
|
||||
self._doc_idx = np.frombuffer(
|
||||
self._bin_buffer,
|
||||
dtype=np.int64,
|
||||
count=self._doc_count,
|
||||
offset=offset + self._sizes.nbytes + self._pointers.nbytes,
|
||||
)
|
||||
|
||||
def __del__(self):
|
||||
self._bin_buffer_mmap._mmap.close()
|
||||
del self._bin_buffer_mmap
|
||||
|
||||
@property
|
||||
def dtype(self):
|
||||
return self._dtype
|
||||
|
||||
@property
|
||||
def sizes(self):
|
||||
return self._sizes
|
||||
|
||||
@property
|
||||
def doc_idx(self):
|
||||
return self._doc_idx
|
||||
|
||||
@lru_cache(maxsize=8)
|
||||
def __getitem__(self, i):
|
||||
return self._pointers[i], self._sizes[i]
|
||||
|
||||
def __len__(self):
|
||||
return self._len
|
||||
|
||||
def __init__(self, path, skip_warmup=False):
|
||||
super().__init__()
|
||||
|
||||
self._path = None
|
||||
self._index = None
|
||||
self._bin_buffer = None
|
||||
|
||||
self._do_init(path, skip_warmup)
|
||||
|
||||
def __getstate__(self):
|
||||
return self._path
|
||||
|
||||
def __setstate__(self, state):
|
||||
self._do_init(state)
|
||||
|
||||
def _do_init(self, path, skip_warmup):
|
||||
self._path = path
|
||||
self._index = self.Index(index_file_path(self._path), skip_warmup)
|
||||
|
||||
if not skip_warmup:
|
||||
print_rank_0(" warming up data mmap file...")
|
||||
_warmup_mmap_file(data_file_path(self._path))
|
||||
print_rank_0(" creating numpy buffer of mmap...")
|
||||
self._bin_buffer_mmap = np.memmap(
|
||||
data_file_path(self._path), mode="r", order="C"
|
||||
)
|
||||
print_rank_0(" creating memory view of numpy buffer...")
|
||||
self._bin_buffer = memoryview(self._bin_buffer_mmap)
|
||||
|
||||
def __del__(self):
|
||||
self._bin_buffer_mmap._mmap.close()
|
||||
del self._bin_buffer_mmap
|
||||
del self._index
|
||||
|
||||
def __len__(self):
|
||||
return len(self._index)
|
||||
|
||||
# @lru_cache(maxsize=8)
|
||||
def __getitem__(self, idx):
|
||||
if isinstance(idx, int):
|
||||
ptr, size = self._index[idx]
|
||||
np_array = np.frombuffer(
|
||||
self._bin_buffer, dtype=self._index.dtype, count=size, offset=ptr
|
||||
)
|
||||
return np_array
|
||||
elif isinstance(idx, slice):
|
||||
start, stop, step = idx.indices(len(self))
|
||||
if step != 1:
|
||||
raise ValueError(
|
||||
"Slices into indexed_dataset must be contiguous")
|
||||
ptr = self._index._pointers[start]
|
||||
sizes = self._index._sizes[idx]
|
||||
offsets = list(accumulate(sizes))
|
||||
total_size = sum(sizes)
|
||||
np_array = np.frombuffer(
|
||||
self._bin_buffer, dtype=self._index.dtype, count=total_size, offset=ptr
|
||||
)
|
||||
sents = np.split(np_array, offsets[:-1])
|
||||
return sents
|
||||
|
||||
def get(self, idx, offset=0, length=None):
|
||||
"""Retrieves a single item from the dataset with the option to only
|
||||
return a portion of the item.
|
||||
|
||||
get(idx) is the same as [idx] but get() does not support slicing.
|
||||
"""
|
||||
ptr, size = self._index[idx]
|
||||
if length is None:
|
||||
length = size - offset
|
||||
ptr += offset * np.dtype(self._index.dtype).itemsize
|
||||
np_array = np.frombuffer(
|
||||
self._bin_buffer, dtype=self._index.dtype, count=length, offset=ptr
|
||||
)
|
||||
return np_array
|
||||
|
||||
@property
|
||||
def sizes(self):
|
||||
return self._index.sizes
|
||||
|
||||
@property
|
||||
def doc_idx(self):
|
||||
return self._index.doc_idx
|
||||
|
||||
def get_doc_idx(self):
|
||||
return self._index._doc_idx
|
||||
|
||||
def set_doc_idx(self, doc_idx_):
|
||||
self._index._doc_idx = doc_idx_
|
||||
|
||||
@property
|
||||
def supports_prefetch(self):
|
||||
return False
|
||||
|
||||
@staticmethod
|
||||
def exists(path):
|
||||
return os.path.exists(index_file_path(path)) and os.path.exists(
|
||||
data_file_path(path)
|
||||
)
|
||||
224
finetune/lora/src/dataset.py
vendored
Normal file
@@ -0,0 +1,224 @@
|
||||
########################################################################################################
|
||||
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
|
||||
########################################################################################################
|
||||
|
||||
import json, math, random, os, sys
|
||||
import numpy as np
|
||||
import torch
|
||||
from torch.utils.data import Dataset
|
||||
from pytorch_lightning.utilities import rank_zero_info
|
||||
from .binidx import MMapIndexedDataset
|
||||
from .utils import MaybeIsPrime
|
||||
|
||||
|
||||
class MyDataset(Dataset):
|
||||
def __init__(self, args):
|
||||
self.args = args
|
||||
|
||||
if args.data_type == "binidx":
|
||||
self.vocab_size = args.vocab_size
|
||||
rank_zero_info(f"Current vocab size = {self.vocab_size} (make sure it's correct)")
|
||||
|
||||
if args.data_file.endswith('/'):
|
||||
d_all = []
|
||||
for p in os.listdir(args.data_file):
|
||||
if p.endswith(".idx"):
|
||||
d_all += [p[:-4]]
|
||||
d_all.sort()
|
||||
rank_zero_info(d_all)
|
||||
exit(0)
|
||||
else:
|
||||
self.data = MMapIndexedDataset(args.data_file)
|
||||
self.data_size = len(self.data._bin_buffer) // self.data._index._dtype_size
|
||||
rank_zero_info(f"Data has {self.data_size} tokens.")
|
||||
|
||||
if args.my_qa_mask > 0:
|
||||
self.data_pile = MMapIndexedDataset('/fsx/BlinkDL/pile/pile_20B_tokenizer_text_document')
|
||||
self.data_pile_size = len(self.data_pile._bin_buffer) // self.data._index._dtype_size
|
||||
|
||||
if args.my_pile_stage > 0:
|
||||
# assert self.data_size == 332115325534 and self.vocab_size == 50277
|
||||
self.samples_per_epoch = args.epoch_steps * args.real_bsz
|
||||
assert self.samples_per_epoch == 40320
|
||||
rank_zero_info(f"########## Pile 20b-tokenized stage {args.my_pile_stage} ##########")
|
||||
dataset_slot = self.data_size // args.ctx_len
|
||||
if args.my_pile_stage != 4:
|
||||
assert MaybeIsPrime(args.magic_prime)
|
||||
assert args.magic_prime % 3 == 2
|
||||
assert args.magic_prime / dataset_slot > 0.99 and args.magic_prime / dataset_slot <= 1
|
||||
elif args.data_type == "numpy":
|
||||
self.data = np.load(args.data_file).astype("int")
|
||||
self.vocab_size = args.vocab_size
|
||||
rank_zero_info("Current vocab size =", self.vocab_size, "(make sure it's correct)")
|
||||
self.data_size = len(self.data)
|
||||
rank_zero_info(f"Data has {self.data_size} tokens.")
|
||||
elif args.data_type == "uint16":
|
||||
self.data = np.fromfile(args.data_file, dtype=np.uint16).astype("int32").reshape(-1, args.my_sample_len)
|
||||
self.vocab_size = args.vocab_size
|
||||
rank_zero_info("Current vocab size =", self.vocab_size, "(make sure it's correct)")
|
||||
self.data_size = self.data.shape[0]
|
||||
rank_zero_info(f"Data has {self.data_size} samples.")
|
||||
elif args.data_type == "wds_img":
|
||||
self.vocab_size = -1
|
||||
self.data_size = -1
|
||||
self.data = None
|
||||
self.error_count = 0
|
||||
else:
|
||||
if args.data_type == "dummy":
|
||||
rank_zero_info("Building dummy data...")
|
||||
self.data = ""
|
||||
for i in range(100000):
|
||||
aa = (i) % 10000
|
||||
bb = (i * i) % 10000
|
||||
cc = aa + bb
|
||||
self.data += f".{aa}+{bb}={cc}."
|
||||
else:
|
||||
self.data = open(args.data_file, "r", encoding=args.data_type).read()
|
||||
rank_zero_info("Building token list...")
|
||||
unique = sorted(list(set(self.data)))
|
||||
self.vocab_size = len(unique)
|
||||
# rank_zero_info()
|
||||
# for u in unique:
|
||||
# print(u, end=' ')
|
||||
# rank_zero_info('\n\n')
|
||||
xx = 0
|
||||
xxObj = {}
|
||||
for u in unique:
|
||||
xxObj[xx] = u
|
||||
xx += 1
|
||||
with open(f"{args.proj_dir}/vocab.json", "w", encoding="utf-16le") as vocab_file:
|
||||
vocab_file.write(json.dumps(xxObj, ensure_ascii=False))
|
||||
self.data_size = len(self.data)
|
||||
rank_zero_info(f"Data has {self.data_size} tokens, {self.vocab_size} vocab size.")
|
||||
self.stoi = {ch: i for i, ch in enumerate(unique)}
|
||||
self.itos = {i: ch for i, ch in enumerate(unique)}
|
||||
|
||||
def __len__(self):
|
||||
return self.args.epoch_steps * self.args.micro_bsz
|
||||
|
||||
def __getitem__(self, idx):
|
||||
args = self.args
|
||||
rank = self.global_rank
|
||||
epoch = self.real_epoch
|
||||
world_size = self.world_size
|
||||
# print(f"epoch {epoch} idx {idx} rank {rank}/{world_size}")
|
||||
|
||||
if args.data_type == "wds_img":
|
||||
def init_wds(self, bias=0):
|
||||
def identity(x):
|
||||
return x
|
||||
import webdataset as wds
|
||||
import torchvision.transforms as transforms
|
||||
# img_transform = transforms.Compose(
|
||||
# [transforms.CenterCrop(256)]
|
||||
# )
|
||||
img_transform = transforms.Compose([
|
||||
transforms.CenterCrop(512),
|
||||
transforms.Resize((args.my_img_size))
|
||||
])
|
||||
self.data_raw = wds.WebDataset(args.data_file, resampled=True).shuffle(10000, initial=1000, rng=random.Random(epoch*100000+rank+bias*1e9)).decode("torchrgb").to_tuple("jpg", "json", "txt").map_tuple(img_transform, identity, identity)
|
||||
for pp in self.data_raw.pipeline:
|
||||
if 'Resampled' in str(pp):
|
||||
pp.deterministic = True
|
||||
def worker_seed():
|
||||
return rank*100000+epoch+bias*1e9
|
||||
pp.worker_seed = worker_seed
|
||||
self.data = iter(self.data_raw)
|
||||
# print(f"WebDataset loaded for rank {rank} epoch {epoch}")
|
||||
if self.data == None:
|
||||
init_wds(self)
|
||||
trial = 0
|
||||
while trial < 10:
|
||||
try:
|
||||
dd = next(self.data) # jpg, json, txt
|
||||
break
|
||||
except:
|
||||
print(f'[dataloader error - epoch {epoch} rank {rank} - trying a new shuffle]')
|
||||
self.error_count += 1
|
||||
init_wds(self, self.error_count)
|
||||
trial += 1
|
||||
pass
|
||||
# print(f"epoch {epoch} idx {idx} rank {rank}/{world_size} {dd[2]}")
|
||||
# with open(f"sample_{rank}.txt", "a", encoding="utf-8") as tmp:
|
||||
# tmp.write(f"epoch {epoch} idx {idx} rank {rank}/{world_size} {int(dd[1]['key'])}\n")
|
||||
return dd[0], dd[2]
|
||||
else:
|
||||
if args.data_type == "uint16":
|
||||
i = np.random.randint(0, self.data_size-1)
|
||||
dix = self.data[i]
|
||||
x = torch.tensor(dix[:-1], dtype=torch.long)
|
||||
y = torch.tensor(dix[1:], dtype=torch.long)
|
||||
else:
|
||||
ctx_len = args.ctx_len
|
||||
req_len = ctx_len + 1
|
||||
magic_prime = args.magic_prime
|
||||
data = self.data
|
||||
|
||||
if args.my_pile_stage > 0 and args.my_pile_stage != 4:
|
||||
ii = 1 + epoch * self.samples_per_epoch + (idx * world_size) + rank
|
||||
|
||||
if args.my_qa_mask > 0:
|
||||
ii_orig = ii
|
||||
if ii % 2 == 0:
|
||||
ii = (ii // 2) * args.magic_prime
|
||||
if args.ctx_len == 1024:
|
||||
magic_prime = 324331313
|
||||
elif args.ctx_len == 2048:
|
||||
magic_prime = 162165671
|
||||
elif args.ctx_len == 4096:
|
||||
magic_prime = 81082817
|
||||
data = self.data_pile
|
||||
else:
|
||||
ii = ii // 2
|
||||
|
||||
factor = (math.sqrt(5) - 1) / 2
|
||||
factor = int(magic_prime * factor)
|
||||
i = ((factor * ii * ii * ii) % magic_prime) * ctx_len
|
||||
if (args.my_qa_mask == 0) or (data == self.data_pile):
|
||||
i = i + args.my_pile_shift
|
||||
# print(f"epoch {epoch} idx {idx} rank {rank}/{world_size} ii {ii} pos {round(i / self.data_size, 3)}")
|
||||
else:
|
||||
# cheat: pick a random spot in dataset
|
||||
i = np.random.randint(0, self.data_size - req_len)
|
||||
|
||||
if args.data_type == "binidx":
|
||||
dix = data.get(idx=0, offset=i, length=req_len).astype(int)
|
||||
elif args.data_type == "numpy":
|
||||
dix = data[i : i + req_len]
|
||||
else:
|
||||
dix = [self.stoi[s] for s in data[i : i + req_len]]
|
||||
|
||||
if args.my_qa_mask == 1:
|
||||
if data == self.data_pile:
|
||||
z = [1] * ctx_len
|
||||
else:
|
||||
z = [0] * ctx_len
|
||||
z_sum = 0
|
||||
isGood = False
|
||||
for i in range(3, ctx_len):
|
||||
if dix[i] == 27 and dix[i-1] == 34 and dix[i-2] == 187 and dix[i-3] == 187:
|
||||
isGood = True
|
||||
if dix[i] == 0:
|
||||
isGood = False
|
||||
if isGood:
|
||||
z[i] = 1
|
||||
z_sum += 1
|
||||
if z_sum == 0:
|
||||
z = [1] * ctx_len
|
||||
i = np.random.randint(0, self.data_pile_size - req_len)
|
||||
dix = self.data_pile.get(idx=0, offset=i, length=req_len).astype(int)
|
||||
z = torch.tensor(z, dtype=torch.bfloat16)
|
||||
|
||||
x = torch.tensor(dix[:-1], dtype=torch.long)
|
||||
y = torch.tensor(dix[1:], dtype=torch.long)
|
||||
|
||||
# if ii_orig < 50:
|
||||
# # if rank == 1:
|
||||
# print('rank', rank, 'i', ii_orig, ii, i, 'x', x[:5], '...', x[-5:])
|
||||
# else:
|
||||
# exit(0)
|
||||
|
||||
if args.my_qa_mask == 1:
|
||||
return x, y, z
|
||||
|
||||
return x, y
|
||||
678
finetune/lora/src/model.py
vendored
Normal file
@@ -0,0 +1,678 @@
|
||||
########################################################################################################
|
||||
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
|
||||
########################################################################################################
|
||||
|
||||
import functools
|
||||
import os, math, gc, importlib
|
||||
import torch
|
||||
# torch._C._jit_set_profiling_executor(True)
|
||||
# torch._C._jit_set_profiling_mode(True)
|
||||
import torch.nn as nn
|
||||
from torch.utils.checkpoint import checkpoint as torch_checkpoint
|
||||
from torch.nn import functional as F
|
||||
import pytorch_lightning as pl
|
||||
from pytorch_lightning.utilities import rank_zero_info, rank_zero_only
|
||||
from pytorch_lightning.strategies import DeepSpeedStrategy
|
||||
if importlib.util.find_spec('deepspeed'):
|
||||
import deepspeed
|
||||
from deepspeed.ops.adam import DeepSpeedCPUAdam, FusedAdam
|
||||
|
||||
# from deepspeed.runtime.fp16.onebit.zoadam import ZeroOneAdam
|
||||
|
||||
LORA_CONFIG = {
|
||||
"r": 0,
|
||||
"alpha": 0,
|
||||
"dropout": 0,
|
||||
"parts": {"att", "ln", "time"},
|
||||
}
|
||||
|
||||
|
||||
try:
|
||||
print('RWKV_MY_TESTING', os.environ["RWKV_MY_TESTING"])
|
||||
except:
|
||||
os.environ["RWKV_MY_TESTING"] = ''
|
||||
|
||||
def __nop(ob):
|
||||
return ob
|
||||
|
||||
|
||||
MyModule = nn.Module
|
||||
MyFunction = __nop
|
||||
if os.environ["RWKV_JIT_ON"] == "1":
|
||||
MyModule = torch.jit.ScriptModule
|
||||
MyFunction = torch.jit.script_method
|
||||
|
||||
|
||||
########################################################################################################
|
||||
# CUDA Kernel
|
||||
########################################################################################################
|
||||
|
||||
T_MAX = int(os.environ["RWKV_T_MAX"]) # TAKES LOTS OF VRAM!
|
||||
# it's possible to go beyond CUDA limitations if you slice the ctx and pass the hidden state in each slice
|
||||
|
||||
from torch.utils.cpp_extension import load
|
||||
|
||||
if os.environ["RWKV_FLOAT_MODE"] == "bf16":
|
||||
wkv_cuda = load(name=f"wkv_{T_MAX}_bf16", sources=["finetune/lora/cuda/wkv_op_bf16.cpp", "finetune/lora/cuda/wkv_cuda_bf16.cu"], verbose=True, extra_cuda_cflags=["-t 4", "-std=c++17", "-res-usage", "--maxrregcount 60", "--use_fast_math", "-O3", "-Xptxas -O3", "--extra-device-vectorization", f"-DTmax={T_MAX}"])
|
||||
class WKV(torch.autograd.Function):
|
||||
@staticmethod
|
||||
def forward(ctx, B, T, C, w, u, k, v):
|
||||
ctx.B = B
|
||||
ctx.T = T
|
||||
ctx.C = C
|
||||
assert T <= T_MAX
|
||||
assert B * C % min(C, 32) == 0
|
||||
w = -torch.exp(w.float().contiguous())
|
||||
u = u.contiguous()
|
||||
k = k.contiguous()
|
||||
v = v.contiguous()
|
||||
y = torch.empty((B, T, C), device=w.device, memory_format=torch.contiguous_format, dtype=torch.bfloat16)
|
||||
wkv_cuda.forward(B, T, C, w, u, k, v, y)
|
||||
ctx.save_for_backward(w, u, k, v, y)
|
||||
return y
|
||||
@staticmethod
|
||||
def backward(ctx, gy):
|
||||
B = ctx.B
|
||||
T = ctx.T
|
||||
C = ctx.C
|
||||
assert T <= T_MAX
|
||||
assert B * C % min(C, 32) == 0
|
||||
w, u, k, v, y = ctx.saved_tensors
|
||||
gw = torch.empty((B, C), device=gy.device, memory_format=torch.contiguous_format, dtype=torch.bfloat16)
|
||||
gu = torch.empty((B, C), device=gy.device, memory_format=torch.contiguous_format, dtype=torch.bfloat16)
|
||||
gk = torch.empty((B, T, C), device=gy.device, memory_format=torch.contiguous_format, dtype=torch.bfloat16)
|
||||
gv = torch.empty((B, T, C), device=gy.device, memory_format=torch.contiguous_format, dtype=torch.bfloat16)
|
||||
wkv_cuda.backward(B, T, C, w, u, k, v, y, gy.contiguous(), gw, gu, gk, gv)
|
||||
gw = torch.sum(gw, dim=0)
|
||||
gu = torch.sum(gu, dim=0)
|
||||
return (None, None, None, gw, gu, gk, gv)
|
||||
else:
|
||||
wkv_cuda = load(name=f"wkv_{T_MAX}", sources=["finetune/lora/cuda/wkv_op.cpp", "finetune/lora/cuda/wkv_cuda.cu"], verbose=True, extra_cuda_cflags=["-res-usage", "--maxrregcount 60", "--use_fast_math", "-O3", "-Xptxas -O3", "--extra-device-vectorization", f"-DTmax={T_MAX}"])
|
||||
class WKV(torch.autograd.Function):
|
||||
@staticmethod
|
||||
def forward(ctx, B, T, C, w, u, k, v):
|
||||
ctx.B = B
|
||||
ctx.T = T
|
||||
ctx.C = C
|
||||
assert T <= T_MAX
|
||||
assert B * C % min(C, 32) == 0
|
||||
if "32" in os.environ["RWKV_FLOAT_MODE"]:
|
||||
w = -torch.exp(w.contiguous())
|
||||
u = u.contiguous()
|
||||
k = k.contiguous()
|
||||
v = v.contiguous()
|
||||
else:
|
||||
w = -torch.exp(w.float().contiguous())
|
||||
u = u.float().contiguous()
|
||||
k = k.float().contiguous()
|
||||
v = v.float().contiguous()
|
||||
y = torch.empty((B, T, C), device=w.device, memory_format=torch.contiguous_format)
|
||||
wkv_cuda.forward(B, T, C, w, u, k, v, y)
|
||||
ctx.save_for_backward(w, u, k, v, y)
|
||||
if "32" in os.environ["RWKV_FLOAT_MODE"]:
|
||||
return y
|
||||
elif os.environ["RWKV_FLOAT_MODE"] == "fp16":
|
||||
return y.half()
|
||||
elif os.environ["RWKV_FLOAT_MODE"] == "bf16":
|
||||
return y.bfloat16()
|
||||
@staticmethod
|
||||
def backward(ctx, gy):
|
||||
B = ctx.B
|
||||
T = ctx.T
|
||||
C = ctx.C
|
||||
assert T <= T_MAX
|
||||
assert B * C % min(C, 32) == 0
|
||||
w, u, k, v, y = ctx.saved_tensors
|
||||
gw = torch.empty((B, C), device=gy.device, memory_format=torch.contiguous_format)
|
||||
gu = torch.empty((B, C), device=gy.device, memory_format=torch.contiguous_format)
|
||||
gk = torch.empty((B, T, C), device=gy.device, memory_format=torch.contiguous_format)
|
||||
gv = torch.empty((B, T, C), device=gy.device, memory_format=torch.contiguous_format)
|
||||
if "32" in os.environ["RWKV_FLOAT_MODE"]:
|
||||
wkv_cuda.backward(B, T, C, w, u, k, v, y, gy.contiguous(), gw, gu, gk, gv)
|
||||
else:
|
||||
wkv_cuda.backward(B, T, C, w, u, k, v, y, gy.float().contiguous(), gw, gu, gk, gv)
|
||||
gw = torch.sum(gw, dim=0)
|
||||
gu = torch.sum(gu, dim=0)
|
||||
if "32" in os.environ["RWKV_FLOAT_MODE"]:
|
||||
return (None, None, None, gw, gu, gk, gv)
|
||||
elif os.environ["RWKV_FLOAT_MODE"] == "fp16":
|
||||
return (None, None, None, gw.half(), gu.half(), gk.half(), gv.half())
|
||||
elif os.environ["RWKV_FLOAT_MODE"] == "bf16":
|
||||
return (None, None, None, gw.bfloat16(), gu.bfloat16(), gk.bfloat16(), gv.bfloat16())
|
||||
|
||||
|
||||
def RUN_CUDA(B, T, C, w, u, k, v):
|
||||
return WKV.apply(B, T, C, w, u, k, v)
|
||||
|
||||
|
||||
########################################################################################################
|
||||
# LoRA
|
||||
########################################################################################################
|
||||
|
||||
|
||||
class LoraLinear(nn.Module):
|
||||
|
||||
def __init__(self, in_features: int, out_features: int, bias: bool):
|
||||
super().__init__()
|
||||
|
||||
self.weight = nn.Parameter(torch.empty((out_features, in_features)))
|
||||
assert bias == False, "Biased LoraLinear not supported"
|
||||
|
||||
r, alpha, dropout = LORA_CONFIG["r"], LORA_CONFIG[
|
||||
"alpha"], LORA_CONFIG["dropout"]
|
||||
self.lora_A = nn.Parameter(torch.empty(r, in_features))
|
||||
self.lora_B = nn.Parameter(torch.empty(out_features, r))
|
||||
self.lora_dropout = nn.Dropout(dropout)
|
||||
self.scaling = alpha / r
|
||||
|
||||
nn.init.kaiming_uniform_(self.weight, a=math.sqrt(5))
|
||||
nn.init.kaiming_uniform_(self.lora_A, a=math.sqrt(5))
|
||||
nn.init.zeros_(self.lora_B)
|
||||
|
||||
def forward(self, x):
|
||||
return (
|
||||
F.linear(x, self.weight) + self.scaling *
|
||||
F.linear(F.linear(self.lora_dropout(x), self.lora_A), self.lora_B))
|
||||
|
||||
|
||||
@functools.wraps(LoraLinear)
|
||||
def make_linear_att(*args, **kwargs):
|
||||
if "att" in LORA_CONFIG["parts"] and LORA_CONFIG["r"] > 0:
|
||||
return LoraLinear(*args, **kwargs)
|
||||
else:
|
||||
return nn.Linear(*args, **kwargs)
|
||||
|
||||
|
||||
@functools.wraps(LoraLinear)
|
||||
def make_linear_ffn(*args, **kwargs):
|
||||
if "ffn" in LORA_CONFIG["parts"] and LORA_CONFIG["r"] > 0:
|
||||
return LoraLinear(*args, **kwargs)
|
||||
else:
|
||||
return nn.Linear(*args, **kwargs)
|
||||
|
||||
|
||||
########################################################################################################
|
||||
# RWKV: RWKV Time-mix + RWKV Channel-mix
|
||||
########################################################################################################
|
||||
|
||||
|
||||
class RWKV_TimeMix(MyModule):
|
||||
def __init__(self, args, layer_id):
|
||||
super().__init__()
|
||||
self.args = args
|
||||
self.layer_id = layer_id
|
||||
self.ctx_len = args.ctx_len
|
||||
self.n_embd = args.n_embd
|
||||
|
||||
with torch.no_grad(): # fancy init
|
||||
ratio_0_to_1 = layer_id / (args.n_layer - 1) # 0 to 1
|
||||
ratio_1_to_almost0 = 1.0 - (layer_id / args.n_layer) # 1 to ~0
|
||||
ddd = torch.ones(1, 1, args.n_embd)
|
||||
for i in range(args.n_embd):
|
||||
ddd[0, 0, i] = i / args.n_embd
|
||||
|
||||
# fancy time_decay
|
||||
decay_speed = torch.ones(args.dim_att)
|
||||
for h in range(args.dim_att):
|
||||
decay_speed[h] = -5 + 8 * (h / (args.dim_att - 1)) ** (0.7 + 1.3 * ratio_0_to_1)
|
||||
self.time_decay = nn.Parameter(decay_speed)
|
||||
# print(layer_id, self.time_decay.flatten()[:3].cpu().numpy(), '...', self.time_decay.flatten()[-3:].cpu().numpy())
|
||||
|
||||
# fancy time_first
|
||||
zigzag = torch.tensor([(i + 1) % 3 - 1 for i in range(args.dim_att)]) * 0.5
|
||||
self.time_first = nn.Parameter(torch.ones(args.dim_att) * math.log(0.3) + zigzag)
|
||||
|
||||
# fancy time_mix
|
||||
self.time_mix_k = nn.Parameter(torch.pow(ddd, ratio_1_to_almost0))
|
||||
self.time_mix_v = nn.Parameter(torch.pow(ddd, ratio_1_to_almost0) + 0.3 * ratio_0_to_1)
|
||||
self.time_mix_r = nn.Parameter(torch.pow(ddd, 0.5 * ratio_1_to_almost0))
|
||||
|
||||
self.time_shift = nn.ZeroPad2d((0, 0, 1, -1))
|
||||
|
||||
self.key = make_linear_att(args.n_embd, args.dim_att, bias=False)
|
||||
self.value = make_linear_att(args.n_embd, args.dim_att, bias=False)
|
||||
self.receptance = make_linear_att(args.n_embd, args.dim_att, bias=False)
|
||||
|
||||
self.output = nn.Linear(args.dim_att, args.n_embd, bias=False)
|
||||
|
||||
if 'a' in os.environ["RWKV_MY_TESTING"]:
|
||||
self.register_buffer("att_mask", torch.tril(torch.ones(args.ctx_len, args.ctx_len)))
|
||||
d_qkv = args.n_embd // 16
|
||||
self.qq = nn.Linear(args.n_embd, d_qkv, bias=False)
|
||||
self.kk = nn.Linear(args.n_embd, d_qkv, bias=False)
|
||||
self.vv = nn.Linear(args.n_embd, d_qkv, bias=False)
|
||||
self.oo = nn.Linear(d_qkv, args.n_embd, bias=False)
|
||||
with torch.no_grad():
|
||||
self.time_mix_qq = nn.Parameter(torch.pow(ddd, ratio_1_to_almost0))
|
||||
self.time_mix_kk = nn.Parameter(torch.pow(ddd, ratio_1_to_almost0))
|
||||
self.time_mix_vv = nn.Parameter(torch.pow(ddd, ratio_1_to_almost0) + 0.3 * ratio_0_to_1)
|
||||
|
||||
if 'a' not in os.environ["RWKV_MY_TESTING"]:
|
||||
@MyFunction
|
||||
def jit_func(self, x):
|
||||
xx = self.time_shift(x) # Mix x with the previous timestep to produce xk, xv, xr
|
||||
xk = x * self.time_mix_k + xx * (1 - self.time_mix_k)
|
||||
xv = x * self.time_mix_v + xx * (1 - self.time_mix_v)
|
||||
xr = x * self.time_mix_r + xx * (1 - self.time_mix_r)
|
||||
k = self.key(xk)
|
||||
v = self.value(xv)
|
||||
r = self.receptance(xr)
|
||||
sr = torch.sigmoid(r)
|
||||
return sr, k, v
|
||||
|
||||
def forward(self, x):
|
||||
B, T, C = x.size() # x = (Batch,Time,Channel)
|
||||
sr, k, v = self.jit_func(x)
|
||||
rwkv = sr * RUN_CUDA(B, T, self.args.dim_att, self.time_decay, self.time_first, k, v)
|
||||
return self.output(rwkv)
|
||||
|
||||
if 'a' in os.environ["RWKV_MY_TESTING"]:
|
||||
@MyFunction
|
||||
def QKV(self, q, k, v):
|
||||
att = (q @ k.transpose(-2, -1)) * (1.0 / math.sqrt(k.size(-1)))
|
||||
att = att.masked_fill(self.att_mask == 0, float('-inf'))
|
||||
att = F.softmax(att, dim = -1)
|
||||
x = att @ v
|
||||
return x
|
||||
|
||||
@MyFunction
|
||||
def jit_funcQKV(self, x):
|
||||
xx = self.time_shift(x) # Mix x with the previous timestep to produce xk, xv, xr
|
||||
xk = x * self.time_mix_k + xx * (1 - self.time_mix_k)
|
||||
xv = x * self.time_mix_v + xx * (1 - self.time_mix_v)
|
||||
xr = x * self.time_mix_r + xx * (1 - self.time_mix_r)
|
||||
xqq = x * self.time_mix_qq + xx * (1 - self.time_mix_qq)
|
||||
xkk = x * self.time_mix_kk + xx * (1 - self.time_mix_kk)
|
||||
xvv = x * self.time_mix_vv + xx * (1 - self.time_mix_vv)
|
||||
k = self.key(xk)
|
||||
v = self.value(xv)
|
||||
r = self.receptance(xr)
|
||||
sr = torch.sigmoid(r)
|
||||
qq = self.qq(xqq)
|
||||
kk = self.kk(xkk)
|
||||
vv = self.vv(xvv)
|
||||
return sr, k, v, qq, kk, vv
|
||||
|
||||
def forward(self, x):
|
||||
B, T, C = x.size() # x = (Batch,Time,Channel)
|
||||
sr, k, v, qq, kk, vv = self.jit_funcQKV(x)
|
||||
rwkv = sr * RUN_CUDA(B, T, self.args.dim_att, self.time_decay, self.time_first, k, v)
|
||||
rwkv = self.output(rwkv) + self.oo(self.QKV(qq, kk, vv))
|
||||
return rwkv
|
||||
|
||||
########################################################################################################
|
||||
|
||||
class RWKV_ChannelMix(MyModule):
|
||||
def __init__(self, args, layer_id):
|
||||
super().__init__()
|
||||
self.args = args
|
||||
self.layer_id = layer_id
|
||||
self.time_shift = nn.ZeroPad2d((0, 0, 1, -1))
|
||||
|
||||
with torch.no_grad(): # fancy init of time_mix
|
||||
ratio_1_to_almost0 = 1.0 - (layer_id / args.n_layer) # 1 to ~0
|
||||
ddd = torch.ones(1, 1, args.n_embd)
|
||||
for i in range(args.n_embd):
|
||||
ddd[0, 0, i] = i / args.n_embd
|
||||
self.time_mix_k = nn.Parameter(torch.pow(ddd, ratio_1_to_almost0))
|
||||
self.time_mix_r = nn.Parameter(torch.pow(ddd, ratio_1_to_almost0))
|
||||
|
||||
self.key = make_linear_ffn(args.n_embd, args.dim_ffn, bias=False)
|
||||
self.receptance = make_linear_ffn(args.n_embd, args.n_embd, bias=False)
|
||||
self.value = make_linear_ffn(args.dim_ffn, args.n_embd, bias=False)
|
||||
|
||||
@MyFunction
|
||||
def forward(self, x):
|
||||
xx = self.time_shift(x)
|
||||
xk = x * self.time_mix_k + xx * (1 - self.time_mix_k)
|
||||
xr = x * self.time_mix_r + xx * (1 - self.time_mix_r)
|
||||
k = self.key(xk)
|
||||
k = torch.square(torch.relu(k))
|
||||
kv = self.value(k)
|
||||
return torch.sigmoid(self.receptance(xr)) * kv
|
||||
|
||||
class MishGLU(MyModule):
|
||||
def __init__(self, args, layer_id):
|
||||
super().__init__()
|
||||
self.args = args
|
||||
self.layer_id = layer_id
|
||||
self.time_shift = nn.ZeroPad2d((0, 0, 1, -1))
|
||||
|
||||
with torch.no_grad():
|
||||
ratio_1_to_almost0 = 1.0 - (layer_id / args.n_layer)
|
||||
|
||||
x = torch.ones(1, 1, args.n_embd)
|
||||
for i in range(args.n_embd):
|
||||
x[0, 0, i] = i / args.n_embd
|
||||
|
||||
self.time_mix_k = nn.Parameter(torch.pow(x, ratio_1_to_almost0))
|
||||
self.time_mix_r = nn.Parameter(torch.pow(x, ratio_1_to_almost0))
|
||||
self.aa = nn.Linear(args.n_embd, args.dim_ffn, bias=False)
|
||||
self.bb = nn.Linear(args.n_embd, args.dim_ffn, bias=False)
|
||||
self.value = nn.Linear(args.dim_ffn, args.n_embd, bias=False)
|
||||
|
||||
@MyFunction
|
||||
def forward(self, x):
|
||||
xx = self.time_shift(x)
|
||||
xa = x * self.time_mix_k + xx * (1 - self.time_mix_k)
|
||||
xb = x * self.time_mix_r + xx * (1 - self.time_mix_r)
|
||||
a = self.aa(xa)
|
||||
b = self.bb(xb)
|
||||
return self.value(a * F.mish(b))
|
||||
|
||||
########################################################################################################
|
||||
# The RWKV Model with our blocks
|
||||
########################################################################################################
|
||||
|
||||
|
||||
class Block(nn.Module):
|
||||
def __init__(self, args, layer_id):
|
||||
super().__init__()
|
||||
self.args = args
|
||||
self.layer_id = layer_id
|
||||
|
||||
self.ln1 = nn.LayerNorm(args.n_embd)
|
||||
self.ln2 = nn.LayerNorm(args.n_embd)
|
||||
|
||||
if self.layer_id == 0:
|
||||
self.ln0 = nn.LayerNorm(args.n_embd)
|
||||
if args.my_pos_emb > 0:
|
||||
self.pos_emb_x = nn.Parameter(torch.zeros((1,args.my_pos_emb,args.n_embd)))
|
||||
self.pos_emb_y = nn.Parameter(torch.zeros((args.my_pos_emb,1,args.n_embd)))
|
||||
|
||||
if self.layer_id == 0 and self.args.pre_ffn > 0:
|
||||
self.ffnPre = RWKV_ChannelMix(args, 0)
|
||||
else:
|
||||
self.att = RWKV_TimeMix(args, layer_id)
|
||||
|
||||
if 'g' in os.environ["RWKV_MY_TESTING"]:
|
||||
self.ffn = MishGLU(args, layer_id)
|
||||
else:
|
||||
self.ffn = RWKV_ChannelMix(args, layer_id)
|
||||
|
||||
if args.tiny_att_dim > 0 and self.layer_id == args.tiny_att_layer:
|
||||
self.tiny_ln = nn.LayerNorm(args.n_embd)
|
||||
self.tiny_q = nn.Linear(args.n_embd, args.tiny_att_dim, bias=False)
|
||||
self.tiny_k = nn.Linear(args.n_embd, args.tiny_att_dim, bias=False)
|
||||
self.tiny_v = nn.Linear(args.n_embd, args.n_embd, bias=False)
|
||||
self.register_buffer("tiny_mask", torch.tril(torch.ones(args.ctx_len, args.ctx_len)))
|
||||
|
||||
def forward(self, x, x_emb=None):
|
||||
args = self.args
|
||||
B, T, C = x.size()
|
||||
if self.layer_id == 0:
|
||||
x = self.ln0(x)
|
||||
if args.my_pos_emb > 0:
|
||||
pos_emb = (self.pos_emb_x + self.pos_emb_y).reshape(T+1, -1)[:-1,:]
|
||||
x = x + pos_emb
|
||||
|
||||
if self.layer_id == 0 and args.pre_ffn > 0:
|
||||
x = x + self.ffnPre(self.ln1(x))
|
||||
else:
|
||||
x = x + self.att(self.ln1(x))
|
||||
x = x + self.ffn(self.ln2(x))
|
||||
|
||||
if args.tiny_att_dim > 0 and self.layer_id == args.tiny_att_layer:
|
||||
xx = self.tiny_ln(x)
|
||||
q = self.tiny_q(xx)[:, :T, :]
|
||||
k = self.tiny_k(xx)[:, :T, :]
|
||||
c = (q @ k.transpose(-2, -1)) * (args.tiny_att_dim ** (-0.5))
|
||||
c = c.masked_fill(self.tiny_mask[:T, :T] == 0, 0)
|
||||
x = x + c @ self.tiny_v(x_emb)
|
||||
return x
|
||||
|
||||
|
||||
class L2Wrap(torch.autograd.Function):
|
||||
@staticmethod
|
||||
def forward(ctx, loss, y):
|
||||
ctx.save_for_backward(y)
|
||||
return loss
|
||||
|
||||
@staticmethod
|
||||
def backward(ctx, grad_output):
|
||||
y = ctx.saved_tensors[0]
|
||||
# to encourage the logits to be close to 0
|
||||
factor = 1e-4 / (y.shape[0] * y.shape[1])
|
||||
maxx, ids = torch.max(y, -1, keepdim=True)
|
||||
gy = torch.zeros_like(y)
|
||||
gy.scatter_(-1, ids, maxx * factor)
|
||||
return (grad_output, gy)
|
||||
|
||||
|
||||
class RWKV(pl.LightningModule):
|
||||
def __init__(self, args):
|
||||
super().__init__()
|
||||
self.args = args
|
||||
if not hasattr(args, 'dim_att'):
|
||||
args.dim_att = args.n_embd
|
||||
if not hasattr(args, 'dim_ffn'):
|
||||
args.dim_ffn = args.n_embd * 4
|
||||
if not hasattr(args, 'tiny_att_layer'):
|
||||
args.tiny_att_layer = -1
|
||||
if not hasattr(args, 'tiny_att_dim'):
|
||||
args.tiny_att_dim = -1
|
||||
|
||||
self.emb = nn.Embedding(args.vocab_size, args.n_embd)
|
||||
|
||||
self.blocks = nn.ModuleList([Block(args, i) for i in range(args.n_layer)])
|
||||
|
||||
self.ln_out = nn.LayerNorm(args.n_embd)
|
||||
self.head = nn.Linear(args.n_embd, args.vocab_size, bias=False)
|
||||
|
||||
if args.head_qk > 0:
|
||||
self.head_q = nn.Linear(args.n_embd, args.head_qk, bias=False)
|
||||
self.head_k = nn.Linear(args.n_embd, args.head_qk, bias=False)
|
||||
self.register_buffer("copy_mask", torch.tril(torch.ones(args.ctx_len, args.ctx_len)))
|
||||
|
||||
def configure_optimizers(self):
|
||||
args = self.args
|
||||
if args.layerwise_lr > 0:
|
||||
lr_1x = set()
|
||||
lr_2x = set()
|
||||
lr_3x = set()
|
||||
for n, p in self.named_parameters():
|
||||
if "time_mix" in n:
|
||||
if args.my_pile_stage == 2:
|
||||
lr_2x.add(n)
|
||||
else:
|
||||
lr_1x.add(n)
|
||||
elif "time_decay" in n:
|
||||
if args.my_pile_stage == 2:
|
||||
lr_3x.add(n)
|
||||
else:
|
||||
lr_2x.add(n)
|
||||
elif "time_first" in n:
|
||||
lr_3x.add(n)
|
||||
else:
|
||||
lr_1x.add(n)
|
||||
lr_1x = sorted(list(lr_1x))
|
||||
lr_2x = sorted(list(lr_2x))
|
||||
lr_3x = sorted(list(lr_3x))
|
||||
# print('1x', lr_1x)
|
||||
# print('2x', lr_2x)
|
||||
# print('3x', lr_3x)
|
||||
param_dict = {n: p for n, p in self.named_parameters()}
|
||||
if args.my_pile_stage == 2:
|
||||
optim_groups = [
|
||||
{"params": [param_dict[n] for n in lr_1x], "weight_decay": 0.0, "my_lr_scale": 1.0},
|
||||
{"params": [param_dict[n] for n in lr_2x], "weight_decay": 0.0, "my_lr_scale": 5.0},# test: 2e-3 / args.lr_init},
|
||||
{"params": [param_dict[n] for n in lr_3x], "weight_decay": 0.0, "my_lr_scale": 5.0},# test: 3e-3 / args.lr_init},
|
||||
]
|
||||
else:
|
||||
optim_groups = [
|
||||
{"params": [param_dict[n] for n in lr_1x], "weight_decay": 0.0, "my_lr_scale": 1.0},
|
||||
{"params": [param_dict[n] for n in lr_2x], "weight_decay": 0.0, "my_lr_scale": 2.0},
|
||||
{"params": [param_dict[n] for n in lr_3x], "weight_decay": 0.0, "my_lr_scale": 3.0},
|
||||
]
|
||||
else:
|
||||
optim_groups = [
|
||||
{"params": [p for n, p in self.named_parameters()], "weight_decay": 0.0},
|
||||
]
|
||||
|
||||
for g in optim_groups:
|
||||
g["params"] = [p for p in g["params"] if p.requires_grad]
|
||||
optim_groups = [g for g in optim_groups if len(g["params"]) > 0]
|
||||
|
||||
if self.deepspeed_offload:
|
||||
return DeepSpeedCPUAdam(optim_groups, lr=self.args.lr_init, betas=self.args.betas, eps=self.args.adam_eps, bias_correction=True, adamw_mode=False, weight_decay=0, amsgrad=False)
|
||||
return FusedAdam(optim_groups, lr=self.args.lr_init, betas=self.args.betas, eps=self.args.adam_eps, bias_correction=True, adam_w_mode=False, weight_decay=0, amsgrad=False)
|
||||
# return ZeroOneAdam(optim_groups, lr=self.args.lr_init, betas=self.args.betas, eps=self.args.adam_eps, bias_correction=True, weight_decay=0, amsgrad=False, cuda_aware=False)
|
||||
|
||||
@property
|
||||
def deepspeed_offload(self) -> bool:
|
||||
strategy = self.trainer.strategy
|
||||
if isinstance(strategy, DeepSpeedStrategy):
|
||||
cfg = strategy.config["zero_optimization"]
|
||||
return cfg.get("offload_optimizer") or cfg.get("offload_param")
|
||||
return False
|
||||
|
||||
def forward(self, idx):
|
||||
args = self.args
|
||||
B, T = idx.size()
|
||||
assert T <= args.ctx_len, "Cannot forward, model ctx_len is exhausted."
|
||||
|
||||
x = self.emb(idx)
|
||||
x_emb = x
|
||||
|
||||
if args.tiny_att_dim > 0:
|
||||
for block in self.blocks:
|
||||
if args.grad_cp == 1:
|
||||
if args.lora:
|
||||
x = torch_checkpoint(block, x, x_emb, use_reentrant=False)
|
||||
else:
|
||||
x = deepspeed.checkpointing.checkpoint(block, x, x_emb)
|
||||
else:
|
||||
x = block(x, x_emb)
|
||||
else:
|
||||
for block in self.blocks:
|
||||
if args.grad_cp == 1:
|
||||
if args.lora:
|
||||
x = torch_checkpoint(block, x, x_emb, use_reentrant=False)
|
||||
else:
|
||||
x = deepspeed.checkpointing.checkpoint(block, x)
|
||||
else:
|
||||
x = block(x)
|
||||
|
||||
x = self.ln_out(x)
|
||||
|
||||
if args.head_qk > 0:
|
||||
q = self.head_q(x)[:, :T, :]
|
||||
k = self.head_k(x)[:, :T, :]
|
||||
c = (q @ k.transpose(-2, -1)) * (1.0 / args.head_qk)
|
||||
c = c.masked_fill(self.copy_mask[:T, :T] == 0, 0)
|
||||
|
||||
if "32" in os.environ["RWKV_FLOAT_MODE"]:
|
||||
c = c @ F.one_hot(idx, num_classes=args.vocab_size)
|
||||
elif os.environ["RWKV_FLOAT_MODE"] == "fp16":
|
||||
c = c @ F.one_hot(idx, num_classes=args.vocab_size).half()
|
||||
elif os.environ["RWKV_FLOAT_MODE"] == "bf16":
|
||||
c = c @ F.one_hot(idx, num_classes=args.vocab_size).bfloat16()
|
||||
|
||||
x = self.head(x) + c
|
||||
else:
|
||||
x = self.head(x)
|
||||
|
||||
return x
|
||||
|
||||
def training_step(self, batch, batch_idx):
|
||||
args = self.args
|
||||
if args.my_qa_mask != 1:
|
||||
idx, targets = batch
|
||||
logits = self(idx)
|
||||
loss = F.cross_entropy(logits.view(-1, logits.size(-1)), targets.view(-1))
|
||||
else:
|
||||
idx, targets, mask = batch
|
||||
mask = mask.view(-1)
|
||||
sum_mask = torch.sum(mask).item()
|
||||
# if sum_mask == 0:
|
||||
# return torch.tensor([0.0], requires_grad=True)
|
||||
|
||||
logits = self(idx)
|
||||
if sum_mask == mask.shape[0]:
|
||||
loss = F.cross_entropy(logits.view(-1, logits.size(-1)), targets.view(-1))
|
||||
# print('rank', self.global_rank, 'loss', loss.item())
|
||||
else:
|
||||
loss = F.cross_entropy(logits.view(-1, logits.size(-1)), targets.view(-1), reduction='none')
|
||||
# loss_raw = loss
|
||||
loss = torch.sum(loss * mask) / sum_mask
|
||||
|
||||
# torch.set_printoptions(threshold=10000)
|
||||
# if True: #self.global_rank == 1:
|
||||
# tmp = ''
|
||||
# sss = 0
|
||||
# ccc = 0
|
||||
# for i in range(mask.shape[0]):
|
||||
# if mask[i] > 0:
|
||||
# tmp += str(idx.view(-1)[i].item()) + ','
|
||||
# sss += loss_raw.view(-1)[i].float().item()
|
||||
# ccc += 1
|
||||
# print('rank', self.global_rank, 'loss', loss.item(), 'lavg', sss / ccc)#, 'tmp', tmp, 'input', idx)
|
||||
|
||||
return L2Wrap.apply(loss, logits)
|
||||
|
||||
def training_step_end(self, batch_parts):
|
||||
all = self.all_gather(batch_parts)
|
||||
if self.trainer.is_global_zero:
|
||||
self.trainer.my_loss_all = all
|
||||
|
||||
def generate_init_weight(self):
|
||||
print(
|
||||
f"""
|
||||
############################################################################
|
||||
#
|
||||
# Init model weight (slow for large models)...
|
||||
#
|
||||
############################################################################
|
||||
"""
|
||||
)
|
||||
m = {}
|
||||
for n in self.state_dict():
|
||||
p = self.state_dict()[n]
|
||||
shape = p.shape
|
||||
|
||||
gain = 1.0
|
||||
scale = 1.0
|
||||
if "ln_" in n or ".ln" in n or "time_" in n or "_mask" in n or "pos_emb" in n or '.mask.' in n:
|
||||
m[n] = p
|
||||
else:
|
||||
if n == "emb.weight":
|
||||
scale = -1 * self.args.lr_init
|
||||
else:
|
||||
if shape[0] > shape[1]:
|
||||
gain = math.sqrt(shape[0] / shape[1])
|
||||
for kk in [".att.key.", ".att.receptance.", ".att.output.", ".att.key.", ".ffn.value.", ".ffn.receptance.", ".ffnPre.value.", ".ffnPre.receptance.", "head_q.", '.oo.', '.rr.']:
|
||||
if kk in n:
|
||||
scale = 0
|
||||
if n == "head.weight":
|
||||
scale = 0.5
|
||||
if "head_k." in n:
|
||||
scale = 0.1
|
||||
if "head_q." in n:
|
||||
scale = 0
|
||||
|
||||
print(f"{str(shape[0]).ljust(5)} {str(shape[1]).ljust(5)} {str(scale).ljust(4)} {n}")
|
||||
|
||||
if self.args.accelerator.upper() == "GPU":
|
||||
m[n] = torch.empty((shape[0], shape[1]), device="cuda")
|
||||
else:
|
||||
m[n] = torch.empty((shape[0], shape[1]))
|
||||
|
||||
if scale == 0:
|
||||
nn.init.zeros_(m[n])
|
||||
elif scale < 0:
|
||||
nn.init.uniform_(m[n], a=scale, b=-scale)
|
||||
else:
|
||||
nn.init.orthogonal_(m[n], gain=gain * scale)
|
||||
|
||||
m[n] = m[n].cpu()
|
||||
if os.environ["RWKV_FLOAT_MODE"] == "fp16":
|
||||
m[n] = m[n].half()
|
||||
elif os.environ["RWKV_FLOAT_MODE"] == "bf16":
|
||||
m[n] = m[n].bfloat16()
|
||||
|
||||
# if n == "emb.weight":
|
||||
# print(m[n])
|
||||
|
||||
gc.collect()
|
||||
torch.cuda.empty_cache()
|
||||
return m
|
||||
203
finetune/lora/src/trainer.py
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
import os, math, time, datetime, subprocess
|
||||
import torch
|
||||
from torch.utils.data import DataLoader
|
||||
import pytorch_lightning as pl
|
||||
from pytorch_lightning.utilities import rank_zero_info, rank_zero_only
|
||||
from .model import LORA_CONFIG
|
||||
|
||||
def my_save(dd, ff):
|
||||
if '14b-run1' not in ff:
|
||||
torch.save(dd, ff)
|
||||
else:
|
||||
fn = ff.split('/')[-1]
|
||||
fff = '/dev/shm/' + fn
|
||||
torch.save(dd, fff)
|
||||
subprocess.Popen(f" aws s3 mv {fff} s3://rwkv-14b-4k/{fn} --quiet", shell=True)
|
||||
|
||||
class train_callback(pl.Callback):
|
||||
def __init__(self, args):
|
||||
super().__init__()
|
||||
self.args = args
|
||||
|
||||
def on_train_batch_start(self, trainer, pl_module, batch, batch_idx):
|
||||
args = self.args
|
||||
# if args.cuda_cleanup > 0:
|
||||
# torch.cuda.empty_cache()
|
||||
real_step = trainer.global_step + args.epoch_begin * args.epoch_steps
|
||||
|
||||
# LR schedule
|
||||
w_step = args.warmup_steps
|
||||
if args.lr_final == args.lr_init or args.epoch_count == 0:
|
||||
lr = args.lr_init
|
||||
else:
|
||||
decay_step = real_step - args.my_pile_edecay * args.epoch_steps
|
||||
decay_total = (args.epoch_count - args.my_pile_edecay) * args.epoch_steps
|
||||
progress = (decay_step - w_step + 1) / (decay_total - w_step)
|
||||
progress = min(1, max(0, progress))
|
||||
|
||||
if args.lr_final == 0 or args.lr_init == 0: # linear decay
|
||||
lr = args.lr_init + (args.lr_final - args.lr_init) * progress
|
||||
else: # exp decay
|
||||
lr = args.lr_init * math.exp(math.log(args.lr_final / args.lr_init) * pow(progress, 1))
|
||||
|
||||
if trainer.global_step < w_step:
|
||||
lr = lr * (0.2 + 0.8 * trainer.global_step / w_step)
|
||||
# if trainer.is_global_zero:
|
||||
# print(trainer.global_step, decay_step, decay_total, w_step, progress, lr)
|
||||
|
||||
for param_group in trainer.optimizers[0].param_groups:
|
||||
if args.layerwise_lr > 0:
|
||||
param_group["lr"] = lr * param_group["my_lr_scale"]
|
||||
# print(param_group["lr"], param_group["my_lr_scale"])
|
||||
else:
|
||||
param_group["lr"] = lr
|
||||
|
||||
trainer.my_lr = lr
|
||||
# rank_zero_info(f"{real_step} {lr}")
|
||||
|
||||
if trainer.global_step == 0:
|
||||
if trainer.is_global_zero: # logging
|
||||
trainer.my_loss_sum = 0
|
||||
trainer.my_loss_count = 0
|
||||
trainer.my_log = open(args.proj_dir + "/train_log.txt", "a")
|
||||
trainer.my_log.write(f"NEW RUN {args.my_timestamp}\n{vars(self.args)}\n")
|
||||
try:
|
||||
print(f"\n{trainer.strategy.config}\n")
|
||||
trainer.my_log.write(f"{trainer.strategy.config}\n")
|
||||
except:
|
||||
pass
|
||||
trainer.my_log.flush()
|
||||
if len(args.wandb) > 0:
|
||||
print("Login to wandb...")
|
||||
import wandb
|
||||
wandb.init(
|
||||
project=args.wandb,
|
||||
name=args.run_name + " " + args.my_timestamp,
|
||||
config=args,
|
||||
save_code=False,
|
||||
)
|
||||
trainer.my_wandb = wandb
|
||||
|
||||
def on_train_batch_end(self, trainer, pl_module, outputs, batch, batch_idx):
|
||||
args = self.args
|
||||
if trainer.is_global_zero: # logging
|
||||
t_now = time.time_ns()
|
||||
token_per_step = args.ctx_len * args.real_bsz
|
||||
real_step = trainer.global_step + args.epoch_begin * args.epoch_steps
|
||||
kt_s = 0
|
||||
try:
|
||||
t_cost = (t_now - trainer.my_time_ns) / 1e9
|
||||
kt_s = token_per_step / t_cost / 1000
|
||||
self.log("REAL it/s", 1.0 / t_cost, prog_bar=True, on_step=True)
|
||||
self.log("Kt/s", kt_s, prog_bar=True, on_step=True)
|
||||
except:
|
||||
pass
|
||||
trainer.my_time_ns = t_now
|
||||
trainer.my_loss = trainer.my_loss_all.float().mean().item()
|
||||
trainer.my_loss_sum += trainer.my_loss
|
||||
trainer.my_loss_count += 1
|
||||
trainer.my_epoch_loss = trainer.my_loss_sum / trainer.my_loss_count
|
||||
self.log("lr", trainer.my_lr, prog_bar=True, on_step=True)
|
||||
self.log("loss", trainer.my_epoch_loss, prog_bar=True, on_step=True)
|
||||
# self.log("s", real_step, prog_bar=True, on_step=True)
|
||||
|
||||
if len(args.wandb) > 0:
|
||||
lll = {"loss": trainer.my_loss, "lr": trainer.my_lr, "Gtokens": real_step * token_per_step / 1e9}
|
||||
if kt_s > 0:
|
||||
lll["kt/s"] = kt_s
|
||||
trainer.my_wandb.log(lll, step=int(real_step))
|
||||
if args.magic_prime > 0:
|
||||
expand_factor = 2 if args.my_qa_mask > 0 else 1
|
||||
if int(real_step) == int(args.magic_prime * expand_factor // args.real_bsz) - 1:
|
||||
to_save_dict = pl_module.state_dict()
|
||||
my_save(
|
||||
to_save_dict,
|
||||
f"{args.proj_dir}/rwkv-final.pth",
|
||||
)
|
||||
|
||||
|
||||
def on_train_epoch_start(self, trainer, pl_module):
|
||||
args = self.args
|
||||
dataset = trainer.train_dataloader.dataset.datasets
|
||||
assert "MyDataset" in str(dataset)
|
||||
dataset.global_rank = trainer.global_rank
|
||||
dataset.real_epoch = int(args.epoch_begin + trainer.current_epoch)
|
||||
dataset.world_size = trainer.world_size
|
||||
# print(f'########## world_size {dataset.world_size} global_rank {dataset.global_rank} real_epoch {dataset.real_epoch} ##########')
|
||||
|
||||
def on_train_epoch_end(self, trainer, pl_module):
|
||||
args = self.args
|
||||
if trainer.is_global_zero: # logging & save state_dict
|
||||
if (args.epoch_save > 0 and trainer.current_epoch % args.epoch_save == 0) or trainer.current_epoch == args.epoch_count - 1:
|
||||
if args.data_type == 'wds_img':
|
||||
raw_dict = pl_module.state_dict()
|
||||
to_save_dict = {}
|
||||
for k in raw_dict:
|
||||
if k.startswith('encoder.') or k.startswith('decoder.'):
|
||||
to_save_dict[k] = raw_dict[k]
|
||||
else:
|
||||
to_save_dict = pl_module.state_dict()
|
||||
|
||||
if args.lora:
|
||||
enable_time_finetune = 'time' in LORA_CONFIG["parts"]
|
||||
enable_ln_finetune = 'ln' in LORA_CONFIG["parts"]
|
||||
lora_dict = {}
|
||||
for name, state in to_save_dict.items():
|
||||
if ('.lora_' in name
|
||||
or (enable_time_finetune and '.time_' in name)
|
||||
or (enable_ln_finetune and '.ln' in name)):
|
||||
lora_dict[name] = state
|
||||
to_save_dict = lora_dict
|
||||
|
||||
try:
|
||||
my_save(
|
||||
to_save_dict,
|
||||
f"{args.proj_dir}/rwkv-{args.epoch_begin + trainer.current_epoch}.pth",
|
||||
)
|
||||
except Exception as e:
|
||||
print('Error\n\n', e, '\n\n')
|
||||
trainer.my_log.write(f"{args.epoch_begin + trainer.current_epoch} {trainer.my_epoch_loss:.6f} {math.exp(trainer.my_epoch_loss):.4f} {trainer.my_lr:.8f} {datetime.datetime.now()} {trainer.current_epoch}\n")
|
||||
trainer.my_log.flush()
|
||||
|
||||
trainer.my_loss_sum = 0
|
||||
trainer.my_loss_count = 0
|
||||
|
||||
|
||||
@rank_zero_only
|
||||
def generate_init_weight(model, init_weight_name):
|
||||
mm = model.generate_init_weight()
|
||||
|
||||
if model.args.my_pile_stage == 1:
|
||||
if len(model.args.load_model) > 0:
|
||||
print(f"Combine weights from {model.args.load_model}...")
|
||||
load_dict = torch.load(model.args.load_model, map_location="cpu")
|
||||
for k in load_dict:
|
||||
assert k in mm
|
||||
src = load_dict[k]
|
||||
try:
|
||||
mm[k] = src.reshape(mm[k].shape)
|
||||
except:
|
||||
tmp = mm[k].squeeze().clone()
|
||||
print(k, src.shape, '-->', mm[k].shape)
|
||||
ss = src.shape[0]
|
||||
dd = tmp.shape[0]
|
||||
for i in range(dd):
|
||||
pos = i / dd * ss
|
||||
if pos >= ss - 1:
|
||||
tmp[i] = src[ss-1]
|
||||
else:
|
||||
p0 = int(math.floor(pos))
|
||||
ii = pos - p0
|
||||
tmp[i] = src[p0] * (1-ii) + src[p0+1] * (ii)
|
||||
mm[k] = tmp.reshape(mm[k].shape)
|
||||
sss = src.squeeze().float().cpu().numpy()
|
||||
print(sss[:10], '...', sss[-10:])
|
||||
mmm = mm[k].squeeze().float().cpu().numpy()
|
||||
print(mmm[:10], '...', mmm[-10:])
|
||||
|
||||
print(f"Save to {init_weight_name}...")
|
||||
torch.save(mm, init_weight_name)
|
||||
|
||||
if model.args.my_pile_stage == 1:
|
||||
print("Done. Now go for stage 2.")
|
||||
exit(0)
|
||||
130
finetune/lora/src/utils.py
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
import json, time, random, os
|
||||
import numpy as np
|
||||
import torch
|
||||
from torch.nn import functional as F
|
||||
|
||||
time_slot = {}
|
||||
time_ref = time.time_ns()
|
||||
|
||||
def record_time(name):
|
||||
if name not in time_slot:
|
||||
time_slot[name] = 1e20
|
||||
tt = (time.time_ns() - time_ref) / 1e9
|
||||
if tt < time_slot[name]:
|
||||
time_slot[name] = tt
|
||||
|
||||
class TOKENIZER():
|
||||
def __init__(self, WORD_NAME, UNKNOWN_CHAR='\ue083'):
|
||||
if 'list' in str(type(WORD_NAME)):
|
||||
self.charMode = False
|
||||
if WORD_NAME[0] == WORD_NAME[1]:
|
||||
from transformers import PreTrainedTokenizerFast
|
||||
self.tokenizer = PreTrainedTokenizerFast(tokenizer_file=WORD_NAME[0])
|
||||
else:
|
||||
from transformers import GPT2TokenizerFast
|
||||
self.tokenizer = GPT2TokenizerFast(WORD_NAME[0], WORD_NAME[1])
|
||||
self.vocab_size = len(self.tokenizer)
|
||||
else:
|
||||
self.charMode = True
|
||||
with open(WORD_NAME + '.json', "r", encoding="utf-16") as result_file:
|
||||
self.word_table = json.load(result_file)
|
||||
|
||||
self.vocab_size = len(self.word_table)
|
||||
|
||||
self.stoi = {v: int(k) for k, v in self.word_table.items()}
|
||||
self.itos = {int(k): v for k, v in self.word_table.items()}
|
||||
|
||||
self.UNKNOWN_CHAR = self.stoi[UNKNOWN_CHAR]
|
||||
|
||||
def refine_context(self, context):
|
||||
context = context.strip().split('\n')
|
||||
for c in range(len(context)):
|
||||
context[c] = context[c].strip().strip('\u3000').strip('\r')
|
||||
context = list(filter(lambda c: c != '', context))
|
||||
context = '\n' + ('\n'.join(context)).strip()
|
||||
if context == '':
|
||||
context = '\n'
|
||||
return context
|
||||
|
||||
def sample_logits(self, out, x, ctx_len, temperature=1.0, top_p_usual=None, top_p_newline=None):
|
||||
# out[self.UNKNOWN_CHAR] = -float('Inf')
|
||||
lastChar = int(x[-1])
|
||||
|
||||
probs = F.softmax(out, dim=-1)
|
||||
|
||||
if self.charMode:
|
||||
if self.itos[lastChar] == '\n':
|
||||
top_p = top_p_newline
|
||||
else:
|
||||
top_p = top_p_usual
|
||||
else:
|
||||
top_p = top_p_usual
|
||||
|
||||
if os.environ["RWKV_RUN_DEVICE"] == "cpu":
|
||||
probs = probs.numpy()
|
||||
sorted_probs = np.sort(probs)[::-1]
|
||||
cumulative_probs = np.cumsum(sorted_probs)
|
||||
cutoff = float(sorted_probs[np.argmax(cumulative_probs > top_p)])
|
||||
probs[probs < cutoff] = 0
|
||||
if temperature != 1.0:
|
||||
probs = probs.pow(1.0 / temperature)
|
||||
probs = probs / np.sum(probs)
|
||||
out = np.random.choice(a=len(probs), p=probs)
|
||||
return out
|
||||
else:
|
||||
sorted_probs = torch.sort(probs, descending=True)[0]
|
||||
cumulative_probs = torch.cumsum(sorted_probs, dim=-1).cpu().numpy()
|
||||
cutoff = float(sorted_probs[np.argmax(cumulative_probs > top_p)])
|
||||
probs[probs < cutoff] = 0
|
||||
if temperature != 1.0:
|
||||
probs = probs.pow(1.0 / temperature)
|
||||
out = torch.multinomial(probs, num_samples=1)[0]
|
||||
return out
|
||||
|
||||
def MaybeIsPrime(number):
|
||||
if FermatPrimalityTest(number) and MillerRabinPrimalityTest(number):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def FermatPrimalityTest(number):
|
||||
if number > 1:
|
||||
for time in range(3):
|
||||
randomNumber = random.randint(2, number) - 1
|
||||
if pow(randomNumber, number - 1, number) != 1:
|
||||
return False
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
|
||||
def MillerRabinPrimalityTest(number):
|
||||
if number == 2:
|
||||
return True
|
||||
elif number == 1 or number % 2 == 0:
|
||||
return False
|
||||
oddPartOfNumber = number - 1
|
||||
timesTwoDividNumber = 0
|
||||
while oddPartOfNumber % 2 == 0:
|
||||
oddPartOfNumber = oddPartOfNumber // 2
|
||||
timesTwoDividNumber = timesTwoDividNumber + 1
|
||||
|
||||
for time in range(3):
|
||||
while True:
|
||||
randomNumber = random.randint(2, number) - 1
|
||||
if randomNumber != 0 and randomNumber != 1:
|
||||
break
|
||||
|
||||
randomNumberWithPower = pow(randomNumber, oddPartOfNumber, number)
|
||||
|
||||
if (randomNumberWithPower != 1) and (randomNumberWithPower != number - 1):
|
||||
iterationNumber = 1
|
||||
|
||||
while (iterationNumber <= timesTwoDividNumber - 1) and (randomNumberWithPower != number - 1):
|
||||
randomNumberWithPower = pow(randomNumberWithPower, 2, number)
|
||||
iterationNumber = iterationNumber + 1
|
||||
if randomNumberWithPower != (number - 1):
|
||||
return False
|
||||
|
||||
return True
|
||||
479
finetune/lora/train.py
vendored
Normal file
@@ -0,0 +1,479 @@
|
||||
########################################################################################################
|
||||
# The RWKV Language Model - https://github.com/BlinkDL/RWKV-LM
|
||||
########################################################################################################
|
||||
|
||||
if __name__ == "__main__":
|
||||
from argparse import ArgumentParser
|
||||
from pytorch_lightning import Trainer
|
||||
from pytorch_lightning.utilities import rank_zero_info, rank_zero_only
|
||||
|
||||
rank_zero_info("########## work in progress ##########")
|
||||
|
||||
########################################################################################################
|
||||
#
|
||||
# example: train a simple L12-D768 RWKV on dummy data
|
||||
#
|
||||
# python train.py --load_model "" --wandb "" --proj_dir "out" \
|
||||
# --data_file "" --data_type "dummy" --vocab_size 0 \
|
||||
# --ctx_len 128 --epoch_steps 1000 --epoch_count 20 --epoch_begin 0 --epoch_save 10 \
|
||||
# --micro_bsz 16 --n_layer 12 --n_embd 768 --pre_ffn 0 --head_qk 0 \
|
||||
# --lr_init 6e-4 --lr_final 1e-5 --warmup_steps 0 --beta1 0.9 --beta2 0.99 --adam_eps 1e-8 \
|
||||
# --accelerator gpu --devices 1 --precision bf16 --strategy ddp_find_unused_parameters_false --grad_cp 0
|
||||
|
||||
# example: train a simple L6-D512 RWKV from scratch on enwik8
|
||||
#
|
||||
# python train.py --load_model "" --wandb "" --proj_dir "out" \
|
||||
# --data_file "../data/enwik8" --data_type "utf-8" --vocab_size 0 \
|
||||
# --ctx_len 512 --epoch_steps 5000 --epoch_count 500 --epoch_begin 0 --epoch_save 5 \
|
||||
# --micro_bsz 12 --n_layer 6 --n_embd 512 --pre_ffn 0 --head_qk 0 \
|
||||
# --lr_init 8e-4 --lr_final 1e-5 --warmup_steps 0 --beta1 0.9 --beta2 0.99 --adam_eps 1e-8 \
|
||||
# --accelerator gpu --devices 1 --precision bf16 --strategy ddp_find_unused_parameters_false --grad_cp 0
|
||||
|
||||
# example: fine-tune RWKV 1.5B using 8xA100 40G = 1.76it/s = 115k token/s, VRAM 37477M
|
||||
#
|
||||
# python train.py --load_model "/fsx/BlinkDL/CODE/FP16/out_1b2/all-8040.pth" --wandb "" --proj_dir "out" \
|
||||
# --data_file "../data/train.npy" --data_type "numpy" --vocab_size 50277 \
|
||||
# --ctx_len 1024 --epoch_steps 1000 --epoch_count 1000 --epoch_begin 0 --epoch_save 5 \
|
||||
# --micro_bsz 8 --n_layer 24 --n_embd 2048 --pre_ffn 0 --head_qk 0 \
|
||||
# --lr_init 1e-5 --lr_final 1e-5 --warmup_steps 0 --beta1 0.9 --beta2 0.999 --adam_eps 1e-8 \
|
||||
# --accelerator gpu --devices 8 --precision bf16 --strategy deepspeed_stage_2 --grad_cp 0
|
||||
|
||||
# example: fine-tune RWKV 1.5B using 1 GPU fp16 (VRAM 16G) NOTE: fp16 might overflow
|
||||
#
|
||||
# python train.py --load_model "/fsx/BlinkDL/CODE/FP16/out_1b2/all-8040.pth" --wandb "" --proj_dir "out" \
|
||||
# --data_file "../data/train.npy" --data_type "numpy" --vocab_size 50277 \
|
||||
# --ctx_len 1024 --epoch_steps 200 --epoch_count 1000 --epoch_begin 0 --epoch_save 1 \
|
||||
# --micro_bsz 11 --n_layer 24 --n_embd 2048 --pre_ffn 0 --head_qk 0 \
|
||||
# --lr_init 1e-5 --lr_final 1e-5 --warmup_steps 0 --beta1 0.9 --beta2 0.999 --adam_eps 1e-8 \
|
||||
# --accelerator gpu --devices 1 --precision fp16 --strategy deepspeed_stage_2_offload --grad_cp 1
|
||||
|
||||
parser = ArgumentParser()
|
||||
|
||||
parser.add_argument("--load_model", default="", type=str) # full path, with .pth
|
||||
parser.add_argument(
|
||||
"--wandb", default="", type=str
|
||||
) # wandb project name. if "" then don't use wandb
|
||||
parser.add_argument("--proj_dir", default="out", type=str)
|
||||
parser.add_argument("--random_seed", default="-1", type=int)
|
||||
|
||||
parser.add_argument("--data_file", default="", type=str)
|
||||
parser.add_argument("--data_type", default="utf-8", type=str)
|
||||
parser.add_argument(
|
||||
"--vocab_size", default=0, type=int
|
||||
) # vocab_size = 0 means auto (for char-level LM and .txt data)
|
||||
|
||||
parser.add_argument("--ctx_len", default=1024, type=int)
|
||||
parser.add_argument(
|
||||
"--epoch_steps", default=1000, type=int
|
||||
) # a mini "epoch" has [epoch_steps] steps
|
||||
parser.add_argument(
|
||||
"--epoch_count", default=500, type=int
|
||||
) # train for this many "epochs". will continue afterwards with lr = lr_final
|
||||
parser.add_argument(
|
||||
"--epoch_begin", default=0, type=int
|
||||
) # if you load a model trained for x "epochs", set epoch_begin = x
|
||||
parser.add_argument(
|
||||
"--epoch_save", default=5, type=int
|
||||
) # save the model every [epoch_save] "epochs"
|
||||
|
||||
parser.add_argument(
|
||||
"--micro_bsz", default=12, type=int
|
||||
) # micro batch size (batch size per GPU)
|
||||
parser.add_argument("--n_layer", default=6, type=int)
|
||||
parser.add_argument("--n_embd", default=512, type=int)
|
||||
parser.add_argument("--dim_att", default=0, type=int)
|
||||
parser.add_argument("--dim_ffn", default=0, type=int)
|
||||
parser.add_argument(
|
||||
"--pre_ffn", default=0, type=int
|
||||
) # replace first att layer by ffn (sometimes better)
|
||||
parser.add_argument("--head_qk", default=0, type=int) # my headQK trick
|
||||
parser.add_argument("--tiny_att_dim", default=0, type=int) # tiny attention dim
|
||||
parser.add_argument(
|
||||
"--tiny_att_layer", default=-999, type=int
|
||||
) # tiny attention @ which layer
|
||||
|
||||
parser.add_argument(
|
||||
"--lr_init", default=6e-4, type=float
|
||||
) # 6e-4 for L12-D768, 4e-4 for L24-D1024, 3e-4 for L24-D2048
|
||||
parser.add_argument("--lr_final", default=1e-5, type=float)
|
||||
parser.add_argument(
|
||||
"--warmup_steps", default=0, type=int
|
||||
) # try 50 if you load a model
|
||||
parser.add_argument("--beta1", default=0.9, type=float)
|
||||
parser.add_argument(
|
||||
"--beta2", default=0.99, type=float
|
||||
) # use 0.999 when your model is close to convergence
|
||||
parser.add_argument("--adam_eps", default=1e-8, type=float)
|
||||
|
||||
parser.add_argument(
|
||||
"--grad_cp", default=0, type=int
|
||||
) # gradient checkpt: saves VRAM, but slower
|
||||
parser.add_argument("--my_pile_stage", default=0, type=int) # my special pile mode
|
||||
parser.add_argument(
|
||||
"--my_pile_shift", default=-1, type=int
|
||||
) # my special pile mode - text shift
|
||||
parser.add_argument("--my_pile_edecay", default=0, type=int)
|
||||
parser.add_argument(
|
||||
"--layerwise_lr", default=1, type=int
|
||||
) # layerwise lr for faster convergence (but slower it/s)
|
||||
parser.add_argument(
|
||||
"--ds_bucket_mb", default=200, type=int
|
||||
) # deepspeed bucket size in MB. 200 seems enough
|
||||
# parser.add_argument("--cuda_cleanup", default=0, type=int) # extra cuda cleanup (sometimes helpful)
|
||||
|
||||
parser.add_argument("--my_img_version", default=0, type=str)
|
||||
parser.add_argument("--my_img_size", default=0, type=int)
|
||||
parser.add_argument("--my_img_bit", default=0, type=int)
|
||||
parser.add_argument("--my_img_clip", default="x", type=str)
|
||||
parser.add_argument("--my_img_clip_scale", default=1, type=float)
|
||||
parser.add_argument("--my_img_l1_scale", default=0, type=float)
|
||||
parser.add_argument("--my_img_encoder", default="x", type=str)
|
||||
# parser.add_argument("--my_img_noise_scale", default=0, type=float)
|
||||
parser.add_argument("--my_sample_len", default=0, type=int)
|
||||
parser.add_argument("--my_ffn_shift", default=1, type=int)
|
||||
parser.add_argument("--my_att_shift", default=1, type=int)
|
||||
parser.add_argument("--my_pos_emb", default=0, type=int)
|
||||
parser.add_argument("--load_partial", default=0, type=int)
|
||||
parser.add_argument("--magic_prime", default=0, type=int)
|
||||
parser.add_argument("--my_qa_mask", default=0, type=int)
|
||||
parser.add_argument("--my_testing", default="", type=str)
|
||||
|
||||
parser.add_argument("--lora", action="store_true")
|
||||
parser.add_argument("--lora_load", default="", type=str)
|
||||
parser.add_argument("--lora_r", default=8, type=int)
|
||||
parser.add_argument("--lora_alpha", default=32, type=float)
|
||||
parser.add_argument("--lora_dropout", default=0.01, type=float)
|
||||
parser.add_argument("--lora_parts", default="att,ln,time", type=str)
|
||||
|
||||
parser = Trainer.add_argparse_args(parser)
|
||||
args = parser.parse_args()
|
||||
|
||||
########################################################################################################
|
||||
|
||||
import os, warnings, math, datetime, sys, time, importlib
|
||||
import numpy as np
|
||||
import torch
|
||||
from torch.utils.data import DataLoader
|
||||
|
||||
if "deepspeed" in args.strategy:
|
||||
import deepspeed
|
||||
import pytorch_lightning as pl
|
||||
from pytorch_lightning import seed_everything
|
||||
|
||||
if args.random_seed >= 0:
|
||||
print(
|
||||
f"########## WARNING: GLOBAL SEED {args.random_seed} THIS WILL AFFECT MULTIGPU SAMPLING ##########\n"
|
||||
* 3
|
||||
)
|
||||
seed_everything(args.random_seed)
|
||||
|
||||
np.set_printoptions(precision=4, suppress=True, linewidth=200)
|
||||
warnings.filterwarnings(
|
||||
"ignore", ".*Consider increasing the value of the `num_workers` argument*"
|
||||
)
|
||||
warnings.filterwarnings(
|
||||
"ignore", ".*The progress bar already tracks a metric with the*"
|
||||
)
|
||||
# os.environ["WDS_SHOW_SEED"] = "1"
|
||||
|
||||
args.my_timestamp = datetime.datetime.today().strftime("%Y-%m-%d-%H-%M-%S")
|
||||
args.enable_checkpointing = False
|
||||
args.replace_sampler_ddp = False
|
||||
args.logger = False
|
||||
args.gradient_clip_val = 1.0
|
||||
args.num_sanity_val_steps = 0
|
||||
args.check_val_every_n_epoch = int(1e20)
|
||||
args.log_every_n_steps = int(1e20)
|
||||
args.max_epochs = -1 # continue forever
|
||||
args.betas = (args.beta1, args.beta2)
|
||||
args.real_bsz = int(args.num_nodes) * int(args.devices) * args.micro_bsz
|
||||
os.environ["RWKV_T_MAX"] = str(args.ctx_len)
|
||||
os.environ["RWKV_MY_TESTING"] = args.my_testing
|
||||
if args.dim_att <= 0:
|
||||
args.dim_att = args.n_embd
|
||||
if args.dim_ffn <= 0:
|
||||
args.dim_ffn = args.n_embd * 4
|
||||
|
||||
if args.data_type == "wds_img":
|
||||
args.run_name = f"v{args.my_img_version}-{args.my_img_size}-{args.my_img_bit}bit-{args.my_img_clip}x{args.my_img_clip_scale}"
|
||||
args.proj_dir = f"{args.proj_dir}-{args.run_name}"
|
||||
else:
|
||||
args.run_name = (
|
||||
f"{args.vocab_size} ctx{args.ctx_len} L{args.n_layer} D{args.n_embd}"
|
||||
)
|
||||
if not os.path.exists(args.proj_dir):
|
||||
os.makedirs(args.proj_dir)
|
||||
|
||||
if args.my_pile_stage > 0:
|
||||
magic_prime_bak = args.magic_prime
|
||||
if args.ctx_len == 1024:
|
||||
args.magic_prime = 324331313
|
||||
args.epoch_count = 8043
|
||||
elif args.ctx_len == 2048:
|
||||
args.magic_prime = 162165671
|
||||
args.epoch_count = 4021
|
||||
elif args.ctx_len == 4096:
|
||||
args.magic_prime = 81082817
|
||||
args.epoch_count = 2010
|
||||
if args.my_pile_shift < 0:
|
||||
if args.ctx_len == 1024:
|
||||
args.my_pile_shift = 0
|
||||
elif args.ctx_len == 2048:
|
||||
args.my_pile_shift = 512
|
||||
elif args.ctx_len == 4096:
|
||||
args.my_pile_shift = 768
|
||||
|
||||
if magic_prime_bak > 0:
|
||||
args.magic_prime = magic_prime_bak
|
||||
|
||||
args.epoch_steps = 40320 // args.real_bsz
|
||||
assert args.epoch_steps * args.real_bsz == 40320
|
||||
if args.my_pile_stage == 2:
|
||||
assert args.lr_final == args.lr_init
|
||||
if args.my_pile_stage >= 2: # find latest saved model
|
||||
list_p = []
|
||||
for p in os.listdir(args.proj_dir):
|
||||
if p.startswith("rwkv") and p.endswith(".pth"):
|
||||
p = ((p.split("-"))[1].split("."))[0]
|
||||
if p == "init":
|
||||
p = -1
|
||||
else:
|
||||
p = int(p)
|
||||
list_p += [p]
|
||||
list_p.sort()
|
||||
max_p = list_p[-1]
|
||||
if len(list_p) > 1:
|
||||
args.my_pile_prev_p = list_p[-2] # in case max_p is corrupted
|
||||
if max_p == -1:
|
||||
args.load_model = f"{args.proj_dir}/rwkv-init.pth"
|
||||
else:
|
||||
args.load_model = f"{args.proj_dir}/rwkv-{max_p}.pth"
|
||||
if args.my_pile_stage == 2:
|
||||
args.warmup_steps = 10
|
||||
else:
|
||||
args.warmup_steps = 30
|
||||
args.epoch_begin = max_p + 1
|
||||
|
||||
samples_per_epoch = args.epoch_steps * args.real_bsz
|
||||
tokens_per_epoch = samples_per_epoch * args.ctx_len
|
||||
rank_zero_info(
|
||||
f"""
|
||||
############################################################################
|
||||
#
|
||||
# RWKV-4 {args.precision.upper()} on {args.num_nodes}x{args.devices} {args.accelerator.upper()}, bsz {args.num_nodes}x{args.devices}x{args.micro_bsz}={args.real_bsz}, {args.strategy} {'with grad_cp' if args.grad_cp > 0 else ''}
|
||||
#
|
||||
# Data = {args.data_file} ({args.data_type}), ProjDir = {args.proj_dir}
|
||||
#
|
||||
# Epoch = {args.epoch_begin} to {args.epoch_begin + args.epoch_count - 1} (will continue afterwards), save every {args.epoch_save} epoch
|
||||
#
|
||||
# Each "epoch" = {args.epoch_steps} steps, {samples_per_epoch} samples, {tokens_per_epoch} tokens
|
||||
#
|
||||
# Model = {args.n_layer} n_layer, {args.n_embd} n_embd, {args.ctx_len} ctx_len
|
||||
# LoRA = {f'enabled, {args.lora_r} r, {args.lora_alpha} alpha, {args.lora_dropout} dropout, on {args.lora_parts}' if args.lora else 'disabled'}
|
||||
#
|
||||
# Adam = lr {args.lr_init} to {args.lr_final}, warmup {args.warmup_steps} steps, beta {args.betas}, eps {args.adam_eps}
|
||||
#
|
||||
# Found torch {torch.__version__}, recommend 1.13.1+cu117 or newer
|
||||
# Found deepspeed {deepspeed.__version__ if importlib.util.find_spec('deepspeed') else 'None'}, recommend 0.7.0 (faster than newer versions)
|
||||
# Found pytorch_lightning {pl.__version__}, recommend 1.9.1 or newer
|
||||
#
|
||||
############################################################################
|
||||
"""
|
||||
)
|
||||
rank_zero_info(str(vars(args)) + "\n")
|
||||
|
||||
assert args.data_type in [
|
||||
"utf-8",
|
||||
"utf-16le",
|
||||
"numpy",
|
||||
"binidx",
|
||||
"dummy",
|
||||
"wds_img",
|
||||
"uint16",
|
||||
]
|
||||
|
||||
if args.lr_final == 0 or args.lr_init == 0:
|
||||
rank_zero_info(
|
||||
"\n\nNote: lr_final = 0 or lr_init = 0. Using linear LR schedule instead.\n\n"
|
||||
)
|
||||
|
||||
assert args.precision in ["fp32", "tf32", "fp16", "bf16"]
|
||||
os.environ["RWKV_FLOAT_MODE"] = args.precision
|
||||
if args.precision == "fp32":
|
||||
for i in range(10):
|
||||
rank_zero_info(
|
||||
"\n\nNote: you are using fp32 (very slow). Try bf16 / tf32 for faster training.\n\n"
|
||||
)
|
||||
if args.precision == "fp16":
|
||||
rank_zero_info(
|
||||
"\n\nNote: you are using fp16 (might overflow). Try bf16 / tf32 for stable training.\n\n"
|
||||
)
|
||||
|
||||
os.environ["RWKV_JIT_ON"] = "1"
|
||||
if "deepspeed_stage_3" in args.strategy:
|
||||
os.environ["RWKV_JIT_ON"] = "0"
|
||||
if args.lora and args.grad_cp == 1:
|
||||
print(
|
||||
"!!!!! LoRA Warning: Gradient Checkpointing requires JIT off, disabling it"
|
||||
)
|
||||
os.environ["RWKV_JIT_ON"] = "0"
|
||||
|
||||
torch.backends.cudnn.benchmark = True
|
||||
torch.backends.cudnn.enabled = True
|
||||
if args.precision == "fp32":
|
||||
torch.backends.cudnn.allow_tf32 = False
|
||||
torch.backends.cuda.matmul.allow_tf32 = False
|
||||
else:
|
||||
torch.backends.cudnn.allow_tf32 = True
|
||||
torch.backends.cuda.matmul.allow_tf32 = True
|
||||
|
||||
if "32" in args.precision:
|
||||
args.precision = 32
|
||||
elif args.precision == "fp16":
|
||||
args.precision = 16
|
||||
else:
|
||||
args.precision = "bf16"
|
||||
|
||||
########################################################################################################
|
||||
|
||||
from src.trainer import train_callback, generate_init_weight
|
||||
from src.dataset import MyDataset
|
||||
|
||||
train_data = MyDataset(args)
|
||||
args.vocab_size = train_data.vocab_size
|
||||
|
||||
if args.data_type == "wds_img":
|
||||
from src.model_img import RWKV_IMG
|
||||
|
||||
assert args.lora, "LoRA not yet supported for RWKV_IMG"
|
||||
model = RWKV_IMG(args)
|
||||
else:
|
||||
from src.model import RWKV, LORA_CONFIG, LoraLinear
|
||||
|
||||
if args.lora:
|
||||
assert args.lora_r > 0, "LoRA should have its `r` > 0"
|
||||
LORA_CONFIG["r"] = args.lora_r
|
||||
LORA_CONFIG["alpha"] = args.lora_alpha
|
||||
LORA_CONFIG["dropout"] = args.lora_dropout
|
||||
LORA_CONFIG["parts"] = set(str(args.lora_parts).split(","))
|
||||
enable_time_finetune = "time" in LORA_CONFIG["parts"]
|
||||
enable_ln_finetune = "ln" in LORA_CONFIG["parts"]
|
||||
model = RWKV(args)
|
||||
# only train lora parameters
|
||||
if args.lora:
|
||||
model.requires_grad_(False)
|
||||
for name, module in model.named_modules():
|
||||
# have to check param name since it may have been wrapped by torchscript
|
||||
if any(n.startswith("lora_") for n, _ in module.named_parameters()):
|
||||
print(f" LoRA training module {name}")
|
||||
for pname, param in module.named_parameters():
|
||||
param.requires_grad = "lora_" in pname
|
||||
elif enable_ln_finetune and ".ln" in name:
|
||||
print(f" LoRA additionally training module {name}")
|
||||
for param in module.parameters():
|
||||
param.requires_grad = True
|
||||
elif enable_time_finetune and any(
|
||||
n.startswith("time") for n, _ in module.named_parameters()
|
||||
):
|
||||
for pname, param in module.named_parameters():
|
||||
if pname.startswith("time"):
|
||||
print(f" LoRA additionally training parameter {pname}")
|
||||
param.requires_grad = True
|
||||
|
||||
if (
|
||||
len(args.load_model) == 0 or args.my_pile_stage == 1
|
||||
): # shall we build the initial weights?
|
||||
init_weight_name = f"{args.proj_dir}/rwkv-init.pth"
|
||||
generate_init_weight(model, init_weight_name) # save initial weights
|
||||
args.load_model = init_weight_name
|
||||
|
||||
rank_zero_info(f"########## Loading {args.load_model}... ##########")
|
||||
try:
|
||||
load_dict = torch.load(args.load_model, map_location="cpu")
|
||||
model.load_state_dict(load_dict, strict=(not args.lora))
|
||||
except:
|
||||
rank_zero_info(f"Bad checkpoint {args.load_model}")
|
||||
if args.my_pile_stage >= 2: # try again using another checkpoint
|
||||
max_p = args.my_pile_prev_p
|
||||
if max_p == -1:
|
||||
args.load_model = f"{args.proj_dir}/rwkv-init.pth"
|
||||
else:
|
||||
args.load_model = f"{args.proj_dir}/rwkv-{max_p}.pth"
|
||||
args.epoch_begin = max_p + 1
|
||||
rank_zero_info(f"Trying {args.load_model}")
|
||||
load_dict = torch.load(args.load_model, map_location="cpu")
|
||||
model.load_state_dict(load_dict, strict=(not args.lora))
|
||||
|
||||
if args.load_partial == 1:
|
||||
load_keys = load_dict.keys()
|
||||
for k in model.state_dict():
|
||||
if k not in load_keys:
|
||||
load_dict[k] = model.state_dict()[k]
|
||||
model.load_state_dict(load_dict, strict=(not args.lora))
|
||||
# If using LoRA, the LoRA keys might be missing in the original model
|
||||
# model.load_state_dict(load_dict, strict=(not args.lora))
|
||||
if os.path.isfile(args.lora_load):
|
||||
model.load_state_dict(
|
||||
torch.load(args.lora_load, map_location="cpu"), strict=False
|
||||
)
|
||||
|
||||
trainer: Trainer = Trainer.from_argparse_args(
|
||||
args,
|
||||
callbacks=[train_callback(args)],
|
||||
)
|
||||
|
||||
if (
|
||||
args.lr_init > 1e-4
|
||||
or trainer.world_size * args.micro_bsz * trainer.accumulate_grad_batches < 8
|
||||
):
|
||||
if "I_KNOW_WHAT_IM_DOING" in os.environ:
|
||||
if trainer.global_rank == 0:
|
||||
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
print(
|
||||
f" WARNING: you are using too large LR ({args.lr_init} > 1e-4) or too small global batch size ({trainer.world_size} * {args.micro_bsz} * {trainer.accumulate_grad_batches} < 8)"
|
||||
)
|
||||
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
else:
|
||||
if trainer.global_rank == 0:
|
||||
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
print(
|
||||
f" ERROR: you are using too large LR ({args.lr_init} > 1e-4) or too small global batch size ({trainer.world_size} * {args.micro_bsz} * {trainer.accumulate_grad_batches} < 8)"
|
||||
)
|
||||
print(
|
||||
f" Unless you are sure this is what you want, adjust them accordingly"
|
||||
)
|
||||
print(
|
||||
f' (to suppress this, set environment variable "I_KNOW_WHAT_IM_DOING")'
|
||||
)
|
||||
print("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
|
||||
exit(0)
|
||||
|
||||
if trainer.global_rank == 0:
|
||||
for n in model.state_dict():
|
||||
shape = model.state_dict()[n].shape
|
||||
shape = [i for i in shape if i != 1]
|
||||
if len(shape) > 1:
|
||||
print(f"{str(shape[0]).ljust(5)} {str(shape[1]).ljust(5)} {n}")
|
||||
else:
|
||||
print(f"{str(shape[0]).ljust(5)} {n}")
|
||||
|
||||
if "deepspeed" in args.strategy:
|
||||
trainer.strategy.config["zero_optimization"]["allgather_bucket_size"] = (
|
||||
args.ds_bucket_mb * 1000 * 1000
|
||||
)
|
||||
trainer.strategy.config["zero_optimization"]["reduce_bucket_size"] = (
|
||||
args.ds_bucket_mb * 1000 * 1000
|
||||
)
|
||||
|
||||
# must set shuffle=False, persistent_workers=False (because worker is in another thread)
|
||||
data_loader = DataLoader(
|
||||
train_data,
|
||||
shuffle=False,
|
||||
pin_memory=True,
|
||||
batch_size=args.micro_bsz,
|
||||
num_workers=1,
|
||||
persistent_workers=False,
|
||||
drop_last=True,
|
||||
)
|
||||
|
||||
trainer.fit(model, data_loader)
|
||||
3
finetune/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
torch==1.13.1
|
||||
pytorch_lightning==1.9.5
|
||||
deepspeed
|
||||
449
frontend/package-lock.json
generated
@@ -12,12 +12,15 @@
|
||||
"@fluentui/react-icons": "^2.0.201",
|
||||
"@microsoft/fetch-event-source": "^2.0.1",
|
||||
"@primer/octicons-react": "^19.1.0",
|
||||
"chart.js": "^4.3.0",
|
||||
"classnames": "^2.3.2",
|
||||
"github-markdown-css": "^5.2.0",
|
||||
"i18next": "^22.4.15",
|
||||
"mobx": "^6.9.0",
|
||||
"mobx-react-lite": "^3.4.3",
|
||||
"react": "^18.2.0",
|
||||
"react-beautiful-dnd": "^13.1.1",
|
||||
"react-chartjs-2": "^5.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-i18next": "^12.2.2",
|
||||
"react-markdown": "^8.0.7",
|
||||
@@ -33,6 +36,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.6",
|
||||
"@types/react-beautiful-dnd": "^13.1.4",
|
||||
"@types/react-dom": "^18.2.4",
|
||||
"@types/uuid": "^9.0.1",
|
||||
"@vitejs/plugin-react": "^4.0.0",
|
||||
@@ -56,7 +60,7 @@
|
||||
},
|
||||
"node_modules/@ampproject/remapping": {
|
||||
"version": "2.2.1",
|
||||
"resolved": "https://registry.npmmirror.com/@ampproject/remapping/-/remapping-2.2.1.tgz",
|
||||
"resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.2.1.tgz",
|
||||
"integrity": "sha512-lFMjJTrFL3j7L9yBxwYfCq2k6qqwHyzuUl/XBnif78PWTJYyL/dfowQHWE3sp6U6ZzqWiiIZnpTMO96zhkjwtg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
@@ -68,42 +72,42 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/code-frame": {
|
||||
"version": "7.21.4",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/code-frame/-/code-frame-7.21.4.tgz",
|
||||
"integrity": "sha512-LYvhNKfwWSPpocw8GI7gpK2nq3HSDuEPC/uSYaALSJu9xjsalaaYFOq0Pwt5KmVqwEbZlDu81aLXwBOmD/Fv9g==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.22.5.tgz",
|
||||
"integrity": "sha512-Xmwn266vad+6DAqEB2A6V/CcZVp62BbwVmcOJc2RPuwih1kw02TjQvWVWlcKGbBPd+8/0V5DEkOcizRGYsspYQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/highlight": "^7.18.6"
|
||||
"@babel/highlight": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/compat-data": {
|
||||
"version": "7.21.7",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/compat-data/-/compat-data-7.21.7.tgz",
|
||||
"integrity": "sha512-KYMqFYTaenzMK4yUtf4EW9wc4N9ef80FsbMtkwool5zpwl4YrT1SdWYSTRcT94KO4hannogdS+LxY7L+arP3gA==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/compat-data/-/compat-data-7.22.5.tgz",
|
||||
"integrity": "sha512-4Jc/YuIaYqKnDDz892kPIledykKg12Aw1PYX5i/TY28anJtacvM1Rrr8wbieB9GfEJwlzqT0hUEao0CxEebiDA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/core": {
|
||||
"version": "7.21.8",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/core/-/core-7.21.8.tgz",
|
||||
"integrity": "sha512-YeM22Sondbo523Sz0+CirSPnbj9bG3P0CdHcBZdqUuaeOaYEFbOLoGU7lebvGP6P5J/WE9wOn7u7C4J9HvS1xQ==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/core/-/core-7.22.5.tgz",
|
||||
"integrity": "sha512-SBuTAjg91A3eKOvD+bPEz3LlhHZRNu1nFOVts9lzDJTXshHTjII0BAtDS3Y2DAkdZdDKWVZGVwkDfc4Clxn1dg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@ampproject/remapping": "^2.2.0",
|
||||
"@babel/code-frame": "^7.21.4",
|
||||
"@babel/generator": "^7.21.5",
|
||||
"@babel/helper-compilation-targets": "^7.21.5",
|
||||
"@babel/helper-module-transforms": "^7.21.5",
|
||||
"@babel/helpers": "^7.21.5",
|
||||
"@babel/parser": "^7.21.8",
|
||||
"@babel/template": "^7.20.7",
|
||||
"@babel/traverse": "^7.21.5",
|
||||
"@babel/types": "^7.21.5",
|
||||
"@babel/code-frame": "^7.22.5",
|
||||
"@babel/generator": "^7.22.5",
|
||||
"@babel/helper-compilation-targets": "^7.22.5",
|
||||
"@babel/helper-module-transforms": "^7.22.5",
|
||||
"@babel/helpers": "^7.22.5",
|
||||
"@babel/parser": "^7.22.5",
|
||||
"@babel/template": "^7.22.5",
|
||||
"@babel/traverse": "^7.22.5",
|
||||
"@babel/types": "^7.22.5",
|
||||
"convert-source-map": "^1.7.0",
|
||||
"debug": "^4.1.0",
|
||||
"gensync": "^1.0.0-beta.2",
|
||||
@@ -112,15 +116,19 @@
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
},
|
||||
"funding": {
|
||||
"type": "opencollective",
|
||||
"url": "https://opencollective.com/babel"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/generator": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/generator/-/generator-7.21.5.tgz",
|
||||
"integrity": "sha512-SrKK/sRv8GesIW1bDagf9cCG38IOMYZusoe1dfg0D8aiUe3Amvoj1QtjTPAWcfrZFvIwlleLb0gxzQidL9w14w==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.22.5.tgz",
|
||||
"integrity": "sha512-+lcUbnTRhd0jOewtFSedLyiPsD5tswKkbgcezOqqWFUVNEwoUTlpPOBmvhG7OXWLR4jMdv0czPGH5XbflnD1EA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.21.5",
|
||||
"@babel/types": "^7.22.5",
|
||||
"@jridgewell/gen-mapping": "^0.3.2",
|
||||
"@jridgewell/trace-mapping": "^0.3.17",
|
||||
"jsesc": "^2.5.1"
|
||||
@@ -130,13 +138,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-compilation-targets": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-compilation-targets/-/helper-compilation-targets-7.21.5.tgz",
|
||||
"integrity": "sha512-1RkbFGUKex4lvsB9yhIfWltJM5cZKUftB2eNajaDv3dCMEp49iBG0K14uH8NnX9IPux2+mK7JGEOB0jn48/J6w==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-compilation-targets/-/helper-compilation-targets-7.22.5.tgz",
|
||||
"integrity": "sha512-Ji+ywpHeuqxB8WDxraCiqR0xfhYjiDE/e6k7FuIaANnoOFxAHskHChz4vA1mJC9Lbm01s1PVAGhQY4FUKSkGZw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/compat-data": "^7.21.5",
|
||||
"@babel/helper-validator-option": "^7.21.0",
|
||||
"@babel/compat-data": "^7.22.5",
|
||||
"@babel/helper-validator-option": "^7.22.5",
|
||||
"browserslist": "^4.21.3",
|
||||
"lru-cache": "^5.1.1",
|
||||
"semver": "^6.3.0"
|
||||
@@ -149,151 +157,151 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-environment-visitor": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-environment-visitor/-/helper-environment-visitor-7.21.5.tgz",
|
||||
"integrity": "sha512-IYl4gZ3ETsWocUWgsFZLM5i1BYx9SoemminVEXadgLBa9TdeorzgLKm8wWLA6J1N/kT3Kch8XIk1laNzYoHKvQ==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-environment-visitor/-/helper-environment-visitor-7.22.5.tgz",
|
||||
"integrity": "sha512-XGmhECfVA/5sAt+H+xpSg0mfrHq6FzNr9Oxh7PSEBBRUb/mL7Kz3NICXb194rCqAEdxkhPT1a88teizAFyvk8Q==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-function-name": {
|
||||
"version": "7.21.0",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-function-name/-/helper-function-name-7.21.0.tgz",
|
||||
"integrity": "sha512-HfK1aMRanKHpxemaY2gqBmL04iAPOPRj7DxtNbiDOrJK+gdwkiNRVpCpUJYbUT+aZyemKN8brqTOxzCaG6ExRg==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-function-name/-/helper-function-name-7.22.5.tgz",
|
||||
"integrity": "sha512-wtHSq6jMRE3uF2otvfuD3DIvVhOsSNshQl0Qrd7qC9oQJzHvOL4qQXlQn2916+CXGywIjpGuIkoyZRRxHPiNQQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/template": "^7.20.7",
|
||||
"@babel/types": "^7.21.0"
|
||||
"@babel/template": "^7.22.5",
|
||||
"@babel/types": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-hoist-variables": {
|
||||
"version": "7.18.6",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-hoist-variables/-/helper-hoist-variables-7.18.6.tgz",
|
||||
"integrity": "sha512-UlJQPkFqFULIcyW5sbzgbkxn2FKRgwWiRexcuaR8RNJRy8+LLveqPjwZV/bwrLZCN0eUHD/x8D0heK1ozuoo6Q==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-hoist-variables/-/helper-hoist-variables-7.22.5.tgz",
|
||||
"integrity": "sha512-wGjk9QZVzvknA6yKIUURb8zY3grXCcOZt+/7Wcy8O2uctxhplmUPkOdlgoNhmdVee2c92JXbf1xpMtVNbfoxRw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.18.6"
|
||||
"@babel/types": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-module-imports": {
|
||||
"version": "7.21.4",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-module-imports/-/helper-module-imports-7.21.4.tgz",
|
||||
"integrity": "sha512-orajc5T2PsRYUN3ZryCEFeMDYwyw09c/pZeaQEZPH0MpKzSvn3e0uXsDBu3k03VI+9DBiRo+l22BfKTpKwa/Wg==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-module-imports/-/helper-module-imports-7.22.5.tgz",
|
||||
"integrity": "sha512-8Dl6+HD/cKifutF5qGd/8ZJi84QeAKh+CEe1sBzz8UayBBGg1dAIJrdHOcOM5b2MpzWL2yuotJTtGjETq0qjXg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.21.4"
|
||||
"@babel/types": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-module-transforms": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-module-transforms/-/helper-module-transforms-7.21.5.tgz",
|
||||
"integrity": "sha512-bI2Z9zBGY2q5yMHoBvJ2a9iX3ZOAzJPm7Q8Yz6YeoUjU/Cvhmi2G4QyTNyPBqqXSgTjUxRg3L0xV45HvkNWWBw==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-module-transforms/-/helper-module-transforms-7.22.5.tgz",
|
||||
"integrity": "sha512-+hGKDt/Ze8GFExiVHno/2dvG5IdstpzCq0y4Qc9OJ25D4q3pKfiIP/4Vp3/JvhDkLKsDK2api3q3fpIgiIF5bw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/helper-environment-visitor": "^7.21.5",
|
||||
"@babel/helper-module-imports": "^7.21.4",
|
||||
"@babel/helper-simple-access": "^7.21.5",
|
||||
"@babel/helper-split-export-declaration": "^7.18.6",
|
||||
"@babel/helper-validator-identifier": "^7.19.1",
|
||||
"@babel/template": "^7.20.7",
|
||||
"@babel/traverse": "^7.21.5",
|
||||
"@babel/types": "^7.21.5"
|
||||
"@babel/helper-environment-visitor": "^7.22.5",
|
||||
"@babel/helper-module-imports": "^7.22.5",
|
||||
"@babel/helper-simple-access": "^7.22.5",
|
||||
"@babel/helper-split-export-declaration": "^7.22.5",
|
||||
"@babel/helper-validator-identifier": "^7.22.5",
|
||||
"@babel/template": "^7.22.5",
|
||||
"@babel/traverse": "^7.22.5",
|
||||
"@babel/types": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-plugin-utils": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-plugin-utils/-/helper-plugin-utils-7.21.5.tgz",
|
||||
"integrity": "sha512-0WDaIlXKOX/3KfBK/dwP1oQGiPh6rjMkT7HIRv7i5RR2VUMwrx5ZL0dwBkKx7+SW1zwNdgjHd34IMk5ZjTeHVg==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-plugin-utils/-/helper-plugin-utils-7.22.5.tgz",
|
||||
"integrity": "sha512-uLls06UVKgFG9QD4OeFYLEGteMIAa5kpTPcFL28yuCIIzsf6ZyKZMllKVOCZFhiZ5ptnwX4mtKdWCBE/uT4amg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-simple-access": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-simple-access/-/helper-simple-access-7.21.5.tgz",
|
||||
"integrity": "sha512-ENPDAMC1wAjR0uaCUwliBdiSl1KBJAVnMTzXqi64c2MG8MPR6ii4qf7bSXDqSFbr4W6W028/rf5ivoHop5/mkg==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-simple-access/-/helper-simple-access-7.22.5.tgz",
|
||||
"integrity": "sha512-n0H99E/K+Bika3++WNL17POvo4rKWZ7lZEp1Q+fStVbUi8nxPQEBOlTmCOxW/0JsS56SKKQ+ojAe2pHKJHN35w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.21.5"
|
||||
"@babel/types": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-split-export-declaration": {
|
||||
"version": "7.18.6",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.18.6.tgz",
|
||||
"integrity": "sha512-bde1etTx6ZyTmobl9LLMMQsaizFVZrquTEHOqKeQESMKo4PlObf+8+JA25ZsIpZhT/WEd39+vOdLXAFG/nELpA==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-split-export-declaration/-/helper-split-export-declaration-7.22.5.tgz",
|
||||
"integrity": "sha512-thqK5QFghPKWLhAV321lxF95yCg2K3Ob5yw+M3VHWfdia0IkPXUtoLH8x/6Fh486QUvzhb8YOWHChTVen2/PoQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/types": "^7.18.6"
|
||||
"@babel/types": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-string-parser": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-string-parser/-/helper-string-parser-7.21.5.tgz",
|
||||
"integrity": "sha512-5pTUx3hAJaZIdW99sJ6ZUUgWq/Y+Hja7TowEnLNMm1VivRgZQL3vpBY3qUACVsvw+yQU6+YgfBVmcbLaZtrA1w==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-string-parser/-/helper-string-parser-7.22.5.tgz",
|
||||
"integrity": "sha512-mM4COjgZox8U+JcXQwPijIZLElkgEpO5rsERVDJTc2qfCDfERyob6k5WegS14SX18IIjv+XD+GrqNumY5JRCDw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-validator-identifier": {
|
||||
"version": "7.19.1",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-validator-identifier/-/helper-validator-identifier-7.19.1.tgz",
|
||||
"integrity": "sha512-awrNfaMtnHUr653GgGEs++LlAvW6w+DcPrOliSMXWCKo597CwL5Acf/wWdNkf/tfEQE3mjkeD1YOVZOUV/od1w==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-validator-identifier/-/helper-validator-identifier-7.22.5.tgz",
|
||||
"integrity": "sha512-aJXu+6lErq8ltp+JhkJUfk1MTGyuA4v7f3pA+BJ5HLfNC6nAQ0Cpi9uOquUj8Hehg0aUiHzWQbOVJGao6ztBAQ==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helper-validator-option": {
|
||||
"version": "7.21.0",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helper-validator-option/-/helper-validator-option-7.21.0.tgz",
|
||||
"integrity": "sha512-rmL/B8/f0mKS2baE9ZpyTcTavvEuWhTTW8amjzXNvYG4AwBsqTLikfXsEofsJEfKHf+HQVQbFOHy6o+4cnC/fQ==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helper-validator-option/-/helper-validator-option-7.22.5.tgz",
|
||||
"integrity": "sha512-R3oB6xlIVKUnxNUxbmgq7pKjxpru24zlimpE8WK47fACIlM0II/Hm1RS8IaOI7NgCr6LNS+jl5l75m20npAziw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/helpers": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/helpers/-/helpers-7.21.5.tgz",
|
||||
"integrity": "sha512-BSY+JSlHxOmGsPTydUkPf1MdMQ3M81x5xGCOVgWM3G8XH77sJ292Y2oqcp0CbbgxhqBuI46iUz1tT7hqP7EfgA==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.22.5.tgz",
|
||||
"integrity": "sha512-pSXRmfE1vzcUIDFQcSGA5Mr+GxBV9oiRKDuDxXvWQQBCh8HoIjs/2DlDB7H8smac1IVrB9/xdXj2N3Wol9Cr+Q==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/template": "^7.20.7",
|
||||
"@babel/traverse": "^7.21.5",
|
||||
"@babel/types": "^7.21.5"
|
||||
"@babel/template": "^7.22.5",
|
||||
"@babel/traverse": "^7.22.5",
|
||||
"@babel/types": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/highlight": {
|
||||
"version": "7.18.6",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/highlight/-/highlight-7.18.6.tgz",
|
||||
"integrity": "sha512-u7stbOuYjaPezCuLj29hNW1v64M2Md2qupEKP1fHc7WdOA3DgLh37suiSrZYY7haUB7iBeQZ9P1uiRF359do3g==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/highlight/-/highlight-7.22.5.tgz",
|
||||
"integrity": "sha512-BSKlD1hgnedS5XRnGOljZawtag7H1yPfQp0tdNJCHoH6AZ+Pcm9VvkrK59/Yy593Ypg0zMxH2BxD1VPYUQ7UIw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/helper-validator-identifier": "^7.18.6",
|
||||
"@babel/helper-validator-identifier": "^7.22.5",
|
||||
"chalk": "^2.0.0",
|
||||
"js-tokens": "^4.0.0"
|
||||
},
|
||||
@@ -302,9 +310,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/parser": {
|
||||
"version": "7.21.8",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/parser/-/parser-7.21.8.tgz",
|
||||
"integrity": "sha512-6zavDGdzG3gUqAdWvlLFfk+36RilI+Pwyuuh7HItyeScCWP3k6i8vKclAQ0bM/0y/Kz/xiwvxhMv9MgTJP5gmA==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.22.5.tgz",
|
||||
"integrity": "sha512-DFZMC9LJUG9PLOclRC32G63UXwzqS2koQC8dkx+PLdmt1xSePYpbT/NbsrJy8Q/muXz7o/h/d4A7Fuyixm559Q==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
"parser": "bin/babel-parser.js"
|
||||
@@ -314,12 +322,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/plugin-transform-react-jsx-self": {
|
||||
"version": "7.21.0",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.21.0.tgz",
|
||||
"integrity": "sha512-f/Eq+79JEu+KUANFks9UZCcvydOOGMgF7jBrcwjHa5jTZD8JivnhCJYvmlhR/WTXBWonDExPoW0eO/CR4QJirA==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.22.5.tgz",
|
||||
"integrity": "sha512-nTh2ogNUtxbiSbxaT4Ds6aXnXEipHweN9YRgOX/oNXdf0cCrGn/+2LozFa3lnPV5D90MkjhgckCPBrsoSc1a7g==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "^7.20.2"
|
||||
"@babel/helper-plugin-utils": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
@@ -329,12 +337,12 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/plugin-transform-react-jsx-source": {
|
||||
"version": "7.19.6",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.19.6.tgz",
|
||||
"integrity": "sha512-RpAi004QyMNisst/pvSanoRdJ4q+jMCWyk9zdw/CyLB9j8RXEahodR6l2GyttDRyEVWZtbN+TpLiHJ3t34LbsQ==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-source/-/plugin-transform-react-jsx-source-7.22.5.tgz",
|
||||
"integrity": "sha512-yIiRO6yobeEIaI0RTbIr8iAK9FcBHLtZq0S89ZPjDLQXBA4xvghaKqI0etp/tF3htTM0sazJKKLz9oEiGRtu7w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/helper-plugin-utils": "^7.19.0"
|
||||
"@babel/helper-plugin-utils": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
@@ -355,33 +363,33 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/template": {
|
||||
"version": "7.20.7",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/template/-/template-7.20.7.tgz",
|
||||
"integrity": "sha512-8SegXApWe6VoNw0r9JHpSteLKTpTiLZ4rMlGIm9JQ18KiCtyQiAMEazujAHrUS5flrcqYZa75ukev3P6QmUwUw==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/template/-/template-7.22.5.tgz",
|
||||
"integrity": "sha512-X7yV7eiwAxdj9k94NEylvbVHLiVG1nvzCV2EAowhxLTwODV1jl9UzZ48leOC0sH7OnuHrIkllaBgneUykIcZaw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.18.6",
|
||||
"@babel/parser": "^7.20.7",
|
||||
"@babel/types": "^7.20.7"
|
||||
"@babel/code-frame": "^7.22.5",
|
||||
"@babel/parser": "^7.22.5",
|
||||
"@babel/types": "^7.22.5"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6.9.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/traverse": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/traverse/-/traverse-7.21.5.tgz",
|
||||
"integrity": "sha512-AhQoI3YjWi6u/y/ntv7k48mcrCXmus0t79J9qPNlk/lAsFlCiJ047RmbfMOawySTHtywXhbXgpx/8nXMYd+oFw==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/traverse/-/traverse-7.22.5.tgz",
|
||||
"integrity": "sha512-7DuIjPgERaNo6r+PZwItpjCZEa5vyw4eJGufeLxrPdBXBoLcCJCIasvK6pK/9DVNrLZTLFhUGqaC6X/PA007TQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/code-frame": "^7.21.4",
|
||||
"@babel/generator": "^7.21.5",
|
||||
"@babel/helper-environment-visitor": "^7.21.5",
|
||||
"@babel/helper-function-name": "^7.21.0",
|
||||
"@babel/helper-hoist-variables": "^7.18.6",
|
||||
"@babel/helper-split-export-declaration": "^7.18.6",
|
||||
"@babel/parser": "^7.21.5",
|
||||
"@babel/types": "^7.21.5",
|
||||
"@babel/code-frame": "^7.22.5",
|
||||
"@babel/generator": "^7.22.5",
|
||||
"@babel/helper-environment-visitor": "^7.22.5",
|
||||
"@babel/helper-function-name": "^7.22.5",
|
||||
"@babel/helper-hoist-variables": "^7.22.5",
|
||||
"@babel/helper-split-export-declaration": "^7.22.5",
|
||||
"@babel/parser": "^7.22.5",
|
||||
"@babel/types": "^7.22.5",
|
||||
"debug": "^4.1.0",
|
||||
"globals": "^11.1.0"
|
||||
},
|
||||
@@ -390,13 +398,13 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@babel/types": {
|
||||
"version": "7.21.5",
|
||||
"resolved": "https://registry.npmmirror.com/@babel/types/-/types-7.21.5.tgz",
|
||||
"integrity": "sha512-m4AfNvVF2mVC/F7fDEdH2El3HzUg9It/XsCxZiOTTA3m3qYfcSVSbTfM6Q9xG+hYDniZssYhlXKKUMD5m8tF4Q==",
|
||||
"version": "7.22.5",
|
||||
"resolved": "https://registry.npmjs.org/@babel/types/-/types-7.22.5.tgz",
|
||||
"integrity": "sha512-zo3MIHGOkPOfoRXitsgHLjEXmlDaD/5KU1Uzuc9GNiZPhSqVxVRtxuPaSBZDsYZ9qV88AjtMtWW7ww98loJ9KA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/helper-string-parser": "^7.21.5",
|
||||
"@babel/helper-validator-identifier": "^7.19.1",
|
||||
"@babel/helper-string-parser": "^7.22.5",
|
||||
"@babel/helper-validator-identifier": "^7.22.5",
|
||||
"to-fast-properties": "^2.0.0"
|
||||
},
|
||||
"engines": {
|
||||
@@ -1897,6 +1905,11 @@
|
||||
"integrity": "sha512-XPSJHWmi394fuUuzDnGz1wiKqWfo1yXecHQMRf2l6hztTO+nPru658AyDngaBe7isIxEkRsPR3FZh+s7iVa4Uw==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@kurkle/color": {
|
||||
"version": "0.3.2",
|
||||
"resolved": "https://registry.npmjs.org/@kurkle/color/-/color-0.3.2.tgz",
|
||||
"integrity": "sha512-fuscdXJ9G1qb7W8VdHi+IwRqij3lBkosAm4ydQtEmbY58OzHXqQhvlxqEkoz0yssNVn38bcpRWgA9PP+OGoisw=="
|
||||
},
|
||||
"node_modules/@microsoft/fetch-event-source": {
|
||||
"version": "2.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/@microsoft/fetch-event-source/-/fetch-event-source-2.0.1.tgz",
|
||||
@@ -1980,6 +1993,15 @@
|
||||
"@types/unist": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/hoist-non-react-statics": {
|
||||
"version": "3.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz",
|
||||
"integrity": "sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==",
|
||||
"dependencies": {
|
||||
"@types/react": "*",
|
||||
"hoist-non-react-statics": "^3.3.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/mdast": {
|
||||
"version": "3.0.11",
|
||||
"resolved": "https://registry.npmmirror.com/@types/mdast/-/mdast-3.0.11.tgz",
|
||||
@@ -2013,6 +2035,15 @@
|
||||
"csstype": "^3.0.2"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/react-beautiful-dnd": {
|
||||
"version": "13.1.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/react-beautiful-dnd/-/react-beautiful-dnd-13.1.4.tgz",
|
||||
"integrity": "sha512-4bIBdzOr0aavN+88q3C7Pgz+xkb7tz3whORYrmSj77wfVEMfiWiooIwVWFR7KM2e+uGTe5BVrXqSfb0aHeflJA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@types/react": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/react-dom": {
|
||||
"version": "18.2.4",
|
||||
"resolved": "https://registry.npmmirror.com/@types/react-dom/-/react-dom-18.2.4.tgz",
|
||||
@@ -2021,6 +2052,17 @@
|
||||
"@types/react": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/react-redux": {
|
||||
"version": "7.1.25",
|
||||
"resolved": "https://registry.npmjs.org/@types/react-redux/-/react-redux-7.1.25.tgz",
|
||||
"integrity": "sha512-bAGh4e+w5D8dajd6InASVIyCo4pZLJ66oLb80F9OBLO1gKESbZcRCJpTT6uLXX+HAB57zw1WTdwJdAsewuTweg==",
|
||||
"dependencies": {
|
||||
"@types/hoist-non-react-statics": "^3.3.0",
|
||||
"@types/react": "*",
|
||||
"hoist-non-react-statics": "^3.3.0",
|
||||
"redux": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/scheduler": {
|
||||
"version": "0.16.3",
|
||||
"resolved": "https://registry.npmmirror.com/@types/scheduler/-/scheduler-0.16.3.tgz",
|
||||
@@ -2038,14 +2080,14 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/@vitejs/plugin-react": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/@vitejs/plugin-react/-/plugin-react-4.0.0.tgz",
|
||||
"integrity": "sha512-HX0XzMjL3hhOYm+0s95pb0Z7F8O81G7joUHgfDd/9J/ZZf5k4xX6QAMFkKsHFxaHlf6X7GD7+XuaZ66ULiJuhQ==",
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/@vitejs/plugin-react/-/plugin-react-4.0.1.tgz",
|
||||
"integrity": "sha512-g25lL98essfeSj43HJ0o4DMp0325XK0ITkxpgChzJU/CyemgyChtlxfnRbjfwxDGCTRxTiXtQAsdebQXKMRSOA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.21.4",
|
||||
"@babel/plugin-transform-react-jsx-self": "^7.21.0",
|
||||
"@babel/plugin-transform-react-jsx-source": "^7.19.6",
|
||||
"@babel/core": "^7.22.5",
|
||||
"@babel/plugin-transform-react-jsx-self": "^7.22.5",
|
||||
"@babel/plugin-transform-react-jsx-source": "^7.22.5",
|
||||
"react-refresh": "^0.14.0"
|
||||
},
|
||||
"engines": {
|
||||
@@ -2066,7 +2108,7 @@
|
||||
},
|
||||
"node_modules/ansi-styles": {
|
||||
"version": "3.2.1",
|
||||
"resolved": "https://registry.npmmirror.com/ansi-styles/-/ansi-styles-3.2.1.tgz",
|
||||
"resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz",
|
||||
"integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
@@ -2206,7 +2248,7 @@
|
||||
},
|
||||
"node_modules/chalk": {
|
||||
"version": "2.4.2",
|
||||
"resolved": "https://registry.npmmirror.com/chalk/-/chalk-2.4.2.tgz",
|
||||
"resolved": "https://registry.npmjs.org/chalk/-/chalk-2.4.2.tgz",
|
||||
"integrity": "sha512-Mti+f9lpJNcwF4tWV8/OrTTtF1gZi+f8FqlyAdouralcFWFQWF2+NgCHShjkCb+IFBLq9buZwE1xckQU4peSuQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
@@ -2223,6 +2265,17 @@
|
||||
"resolved": "https://registry.npmmirror.com/character-entities/-/character-entities-2.0.2.tgz",
|
||||
"integrity": "sha512-shx7oQ0Awen/BRIdkjkvz54PnEEI/EjwXDSIZp86/KKdbafHh1Df/RYGBhn4hbe2+uKC9FnT5UCEdyPz3ai9hQ=="
|
||||
},
|
||||
"node_modules/chart.js": {
|
||||
"version": "4.3.0",
|
||||
"resolved": "https://registry.npmjs.org/chart.js/-/chart.js-4.3.0.tgz",
|
||||
"integrity": "sha512-ynG0E79xGfMaV2xAHdbhwiPLczxnNNnasrmPEXriXsPJGjmhOBYzFVEsB65w2qMDz+CaBJJuJD0inE/ab/h36g==",
|
||||
"dependencies": {
|
||||
"@kurkle/color": "^0.3.0"
|
||||
},
|
||||
"engines": {
|
||||
"pnpm": ">=7"
|
||||
}
|
||||
},
|
||||
"node_modules/chokidar": {
|
||||
"version": "3.5.3",
|
||||
"resolved": "https://registry.npmmirror.com/chokidar/-/chokidar-3.5.3.tgz",
|
||||
@@ -2285,7 +2338,7 @@
|
||||
},
|
||||
"node_modules/color-convert": {
|
||||
"version": "1.9.3",
|
||||
"resolved": "https://registry.npmmirror.com/color-convert/-/color-convert-1.9.3.tgz",
|
||||
"resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz",
|
||||
"integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
@@ -2294,7 +2347,7 @@
|
||||
},
|
||||
"node_modules/color-name": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmmirror.com/color-name/-/color-name-1.1.3.tgz",
|
||||
"resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz",
|
||||
"integrity": "sha512-72fSenhMw2HZMTVHeCA9KCmpEIbzWiQsjN+BHcBbS9vr1mtt+vJjPdksIBNUmKAW8TFUDPJK5SUU3QhE9NEXDw==",
|
||||
"dev": true
|
||||
},
|
||||
@@ -2320,10 +2373,18 @@
|
||||
},
|
||||
"node_modules/convert-source-map": {
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmmirror.com/convert-source-map/-/convert-source-map-1.9.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/convert-source-map/-/convert-source-map-1.9.0.tgz",
|
||||
"integrity": "sha512-ASFBup0Mz1uyiIjANan1jzLQami9z1PoYSZCiiYW2FczPbenXc45FZdBZLzOT+r6+iciuEModtmCti+hjaAk0A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/css-box-model": {
|
||||
"version": "1.2.1",
|
||||
"resolved": "https://registry.npmjs.org/css-box-model/-/css-box-model-1.2.1.tgz",
|
||||
"integrity": "sha512-a7Vr4Q/kd/aw96bnJG332W9V9LkJO69JRcaCYDUqjp6/z0w6VcZjgAcTbgFxEPfBgdnAwlh3iwu+hLopa+flJw==",
|
||||
"dependencies": {
|
||||
"tiny-invariant": "^1.0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/cssesc": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/cssesc/-/cssesc-3.0.0.tgz",
|
||||
@@ -2462,7 +2523,7 @@
|
||||
},
|
||||
"node_modules/escape-string-regexp": {
|
||||
"version": "1.0.5",
|
||||
"resolved": "https://registry.npmmirror.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||
"resolved": "https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz",
|
||||
"integrity": "sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
@@ -2576,7 +2637,7 @@
|
||||
},
|
||||
"node_modules/gensync": {
|
||||
"version": "1.0.0-beta.2",
|
||||
"resolved": "https://registry.npmmirror.com/gensync/-/gensync-1.0.0-beta.2.tgz",
|
||||
"resolved": "https://registry.npmjs.org/gensync/-/gensync-1.0.0-beta.2.tgz",
|
||||
"integrity": "sha512-3hN7NaskYvMDLQY55gnW3NQ+mesEAepTqlg+VEbj7zzqEMBVNhzcGYYeqFo/TlYz6eQiFcp1HcsCZO+nGgS8zg==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
@@ -2628,7 +2689,7 @@
|
||||
},
|
||||
"node_modules/globals": {
|
||||
"version": "11.12.0",
|
||||
"resolved": "https://registry.npmmirror.com/globals/-/globals-11.12.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/globals/-/globals-11.12.0.tgz",
|
||||
"integrity": "sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
@@ -2649,7 +2710,7 @@
|
||||
},
|
||||
"node_modules/has-flag": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/has-flag/-/has-flag-3.0.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||
"integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
@@ -2754,6 +2815,19 @@
|
||||
"node": ">=12.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/hoist-non-react-statics": {
|
||||
"version": "3.3.2",
|
||||
"resolved": "https://registry.npmjs.org/hoist-non-react-statics/-/hoist-non-react-statics-3.3.2.tgz",
|
||||
"integrity": "sha512-/gGivxi8JPKWNm/W0jSmzcMPpfpPLc3dY/6GxhX2hQ9iGj3aDfklV4ET7NjKpSinLpJ5vafa9iiGIEZg10SfBw==",
|
||||
"dependencies": {
|
||||
"react-is": "^16.7.0"
|
||||
}
|
||||
},
|
||||
"node_modules/hoist-non-react-statics/node_modules/react-is": {
|
||||
"version": "16.13.1",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz",
|
||||
"integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ=="
|
||||
},
|
||||
"node_modules/html-parse-stringify": {
|
||||
"version": "3.0.1",
|
||||
"resolved": "https://registry.npmmirror.com/html-parse-stringify/-/html-parse-stringify-3.0.1.tgz",
|
||||
@@ -2918,7 +2992,7 @@
|
||||
},
|
||||
"node_modules/jsesc": {
|
||||
"version": "2.5.2",
|
||||
"resolved": "https://registry.npmmirror.com/jsesc/-/jsesc-2.5.2.tgz",
|
||||
"resolved": "https://registry.npmjs.org/jsesc/-/jsesc-2.5.2.tgz",
|
||||
"integrity": "sha512-OYu7XEzjkCQ3C5Ps3QIZsQfNpqoJyZZA99wd9aWd05NCtC5pWOkShK2mkL6HXQR6/Cy2lbNdPlZBpuQHXE63gA==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
@@ -2930,7 +3004,7 @@
|
||||
},
|
||||
"node_modules/json5": {
|
||||
"version": "2.2.3",
|
||||
"resolved": "https://registry.npmmirror.com/json5/-/json5-2.2.3.tgz",
|
||||
"resolved": "https://registry.npmjs.org/json5/-/json5-2.2.3.tgz",
|
||||
"integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
@@ -2996,7 +3070,7 @@
|
||||
},
|
||||
"node_modules/lru-cache": {
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/lru-cache/-/lru-cache-5.1.1.tgz",
|
||||
"resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-5.1.1.tgz",
|
||||
"integrity": "sha512-KpNARQA3Iwv+jTA0utUVVbrh+Jlrr1Fv0e56GGzAFOXN7dk/FviaDW8LHmK52DlcH4WP2n6gI8vN1aesBFgo9w==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
@@ -3176,6 +3250,11 @@
|
||||
"@types/mdast": "^3.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/memoize-one": {
|
||||
"version": "5.2.1",
|
||||
"resolved": "https://registry.npmjs.org/memoize-one/-/memoize-one-5.2.1.tgz",
|
||||
"integrity": "sha512-zYiwtZUcYyXKo/np96AGZAckk+FWWsUdJ3cHGGmld7+AhvcWmQyGCYUh1hc4Q/pkOhb65dQR/pqCyK0cOaHz4Q=="
|
||||
},
|
||||
"node_modules/merge2": {
|
||||
"version": "1.4.1",
|
||||
"resolved": "https://registry.npmmirror.com/merge2/-/merge2-1.4.1.tgz",
|
||||
@@ -3789,6 +3868,11 @@
|
||||
"integrity": "sha512-NuaNSa6flKT5JaSYQzJok04JzTL1CA6aGhv5rfLW3PgqA+M2ChpZQnAC8h8i4ZFkBS8X5RqkDBHA7r4hej3K9A==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/raf-schd": {
|
||||
"version": "4.0.3",
|
||||
"resolved": "https://registry.npmjs.org/raf-schd/-/raf-schd-4.0.3.tgz",
|
||||
"integrity": "sha512-tQkJl2GRWh83ui2DiPTJz9wEiMN20syf+5oKfB03yYP7ioZcJwsIK8FjrtLwH1m7C7e+Tt2yYBlrOpdT+dyeIQ=="
|
||||
},
|
||||
"node_modules/react": {
|
||||
"version": "18.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/react/-/react-18.2.0.tgz",
|
||||
@@ -3800,6 +3884,33 @@
|
||||
"node": ">=0.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-beautiful-dnd": {
|
||||
"version": "13.1.1",
|
||||
"resolved": "https://registry.npmjs.org/react-beautiful-dnd/-/react-beautiful-dnd-13.1.1.tgz",
|
||||
"integrity": "sha512-0Lvs4tq2VcrEjEgDXHjT98r+63drkKEgqyxdA7qD3mvKwga6a5SscbdLPO2IExotU1jW8L0Ksdl0Cj2AF67nPQ==",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.9.2",
|
||||
"css-box-model": "^1.2.0",
|
||||
"memoize-one": "^5.1.1",
|
||||
"raf-schd": "^4.0.2",
|
||||
"react-redux": "^7.2.0",
|
||||
"redux": "^4.0.4",
|
||||
"use-memo-one": "^1.1.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.5 || ^17.0.0 || ^18.0.0",
|
||||
"react-dom": "^16.8.5 || ^17.0.0 || ^18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-chartjs-2": {
|
||||
"version": "5.2.0",
|
||||
"resolved": "https://registry.npmjs.org/react-chartjs-2/-/react-chartjs-2-5.2.0.tgz",
|
||||
"integrity": "sha512-98iN5aguJyVSxp5U3CblRLH67J8gkfyGNbiK3c+l1QI/G4irHMPQw44aEPmjVag+YKTyQ260NcF82GTQ3bdscA==",
|
||||
"peerDependencies": {
|
||||
"chart.js": "^4.1.1",
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/react-dom": {
|
||||
"version": "18.2.0",
|
||||
"resolved": "https://registry.npmmirror.com/react-dom/-/react-dom-18.2.0.tgz",
|
||||
@@ -3872,6 +3983,35 @@
|
||||
"react": ">=16"
|
||||
}
|
||||
},
|
||||
"node_modules/react-redux": {
|
||||
"version": "7.2.9",
|
||||
"resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.2.9.tgz",
|
||||
"integrity": "sha512-Gx4L3uM182jEEayZfRbI/G11ZpYdNAnBs70lFVMNdHJI76XYtR+7m0MN+eAs7UHBPhWXcnFPaS+9owSCJQHNpQ==",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.15.4",
|
||||
"@types/react-redux": "^7.1.20",
|
||||
"hoist-non-react-statics": "^3.3.2",
|
||||
"loose-envify": "^1.4.0",
|
||||
"prop-types": "^15.7.2",
|
||||
"react-is": "^17.0.2"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.3 || ^17 || ^18"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
"react-dom": {
|
||||
"optional": true
|
||||
},
|
||||
"react-native": {
|
||||
"optional": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"node_modules/react-redux/node_modules/react-is": {
|
||||
"version": "17.0.2",
|
||||
"resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",
|
||||
"integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w=="
|
||||
},
|
||||
"node_modules/react-refresh": {
|
||||
"version": "0.14.0",
|
||||
"resolved": "https://registry.npmmirror.com/react-refresh/-/react-refresh-0.14.0.tgz",
|
||||
@@ -3944,6 +4084,14 @@
|
||||
"node": ">=8.10.0"
|
||||
}
|
||||
},
|
||||
"node_modules/redux": {
|
||||
"version": "4.2.1",
|
||||
"resolved": "https://registry.npmjs.org/redux/-/redux-4.2.1.tgz",
|
||||
"integrity": "sha512-LAUYz4lc+Do8/g7aeRa8JkyDErK6ekstQaqWQrNRW//MY1TvCEpMtpTWvlQ+FPbWCx+Xixu/6SHt5N0HR+SB4w==",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.9.2"
|
||||
}
|
||||
},
|
||||
"node_modules/regenerator-runtime": {
|
||||
"version": "0.13.11",
|
||||
"resolved": "https://registry.npmmirror.com/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz",
|
||||
@@ -4145,7 +4293,7 @@
|
||||
},
|
||||
"node_modules/semver": {
|
||||
"version": "6.3.0",
|
||||
"resolved": "https://registry.npmmirror.com/semver/-/semver-6.3.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz",
|
||||
"integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==",
|
||||
"dev": true,
|
||||
"bin": {
|
||||
@@ -4238,7 +4386,7 @@
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "5.5.0",
|
||||
"resolved": "https://registry.npmmirror.com/supports-color/-/supports-color-5.5.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz",
|
||||
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
@@ -4350,9 +4498,14 @@
|
||||
"node": ">=0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/tiny-invariant": {
|
||||
"version": "1.3.1",
|
||||
"resolved": "https://registry.npmjs.org/tiny-invariant/-/tiny-invariant-1.3.1.tgz",
|
||||
"integrity": "sha512-AD5ih2NlSssTCwsMznbvwMZpJ1cbhkGd2uueNxzv2jDlEeZdU04JQfRnggJQ8DrcVBGjAsCKwFBbDlVNtEMlzw=="
|
||||
},
|
||||
"node_modules/to-fast-properties": {
|
||||
"version": "2.0.0",
|
||||
"resolved": "https://registry.npmmirror.com/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
|
||||
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-2.0.0.tgz",
|
||||
"integrity": "sha512-/OaKK0xYrs3DmxRYqL/yDc+FxFUVYhDlXMhRmv3z915w2HF1tnN1omB354j8VUGO/hbRzyD6Y3sA7v7GS/ceog==",
|
||||
"dev": true,
|
||||
"engines": {
|
||||
@@ -4503,6 +4656,14 @@
|
||||
"react-dom": ">=16.8.0 <19.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/use-memo-one": {
|
||||
"version": "1.1.3",
|
||||
"resolved": "https://registry.npmjs.org/use-memo-one/-/use-memo-one-1.1.3.tgz",
|
||||
"integrity": "sha512-g66/K7ZQGYrI6dy8GLpVcMsBp4s17xNkYJVSMvTEevGy3nDxHOfE6z8BVE22+5G5x7t3+bhzrlTDB7ObrEE0cQ==",
|
||||
"peerDependencies": {
|
||||
"react": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/usehooks-ts": {
|
||||
"version": "2.9.1",
|
||||
"resolved": "https://registry.npmmirror.com/usehooks-ts/-/usehooks-ts-2.9.1.tgz",
|
||||
@@ -4580,9 +4741,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/vite": {
|
||||
"version": "4.3.6",
|
||||
"resolved": "https://registry.npmmirror.com/vite/-/vite-4.3.6.tgz",
|
||||
"integrity": "sha512-cqIyLSbA6gornMS659AXTVKF7cvSHMdKmJJwQ9DXq3lwsT1uZSdktuBRlpHQ8VnOWx0QHtjDwxPpGtyo9Fh/Qg==",
|
||||
"version": "4.3.9",
|
||||
"resolved": "https://registry.npmjs.org/vite/-/vite-4.3.9.tgz",
|
||||
"integrity": "sha512-qsTNZjO9NoJNW7KnOrgYwczm0WctJ8m/yqYAMAK9Lxt4SoySUfS5S8ia9K7JHpa3KEeMfyF8LoJ3c5NeBJy6pg==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"esbuild": "^0.17.5",
|
||||
@@ -4701,7 +4862,7 @@
|
||||
},
|
||||
"node_modules/yallist": {
|
||||
"version": "3.1.1",
|
||||
"resolved": "https://registry.npmmirror.com/yallist/-/yallist-3.1.1.tgz",
|
||||
"resolved": "https://registry.npmjs.org/yallist/-/yallist-3.1.1.tgz",
|
||||
"integrity": "sha512-a4UGQaWPH59mOXUYnAG2ewncQS4i4F43Tv3JoAM+s2VDAmS9NsK8GpDMLrCHPksFT7h3K6TOoUNn2pb7RoXx4g==",
|
||||
"dev": true
|
||||
},
|
||||
|
||||
@@ -13,12 +13,15 @@
|
||||
"@fluentui/react-icons": "^2.0.201",
|
||||
"@microsoft/fetch-event-source": "^2.0.1",
|
||||
"@primer/octicons-react": "^19.1.0",
|
||||
"chart.js": "^4.3.0",
|
||||
"classnames": "^2.3.2",
|
||||
"github-markdown-css": "^5.2.0",
|
||||
"i18next": "^22.4.15",
|
||||
"mobx": "^6.9.0",
|
||||
"mobx-react-lite": "^3.4.3",
|
||||
"react": "^18.2.0",
|
||||
"react-beautiful-dnd": "^13.1.1",
|
||||
"react-chartjs-2": "^5.2.0",
|
||||
"react-dom": "^18.2.0",
|
||||
"react-i18next": "^12.2.2",
|
||||
"react-markdown": "^8.0.7",
|
||||
@@ -34,6 +37,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/react": "^18.2.6",
|
||||
"@types/react-beautiful-dnd": "^13.1.4",
|
||||
"@types/react-dom": "^18.2.4",
|
||||
"@types/uuid": "^9.0.1",
|
||||
"@vitejs/plugin-react": "^4.0.0",
|
||||
|
||||
@@ -28,10 +28,10 @@ import { FC, useEffect, useState } from 'react';
|
||||
import { Route, Routes, useLocation, useNavigate } from 'react-router';
|
||||
import { pages } from './pages';
|
||||
import { useMediaQuery } from 'usehooks-ts';
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
import commonStore from './stores/commonStore';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { CustomToastContainer } from './components/CustomToastContainer';
|
||||
|
||||
const App: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
@@ -87,21 +87,7 @@ const App: FC = observer(() => {
|
||||
</Routes>
|
||||
</div>
|
||||
</div>
|
||||
<ToastContainer
|
||||
style={{
|
||||
width: '350px'
|
||||
}}
|
||||
position="top-center"
|
||||
autoClose={4000}
|
||||
pauseOnHover={true}
|
||||
hideProgressBar={true}
|
||||
newestOnTop={true}
|
||||
closeOnClick={false}
|
||||
rtl={false}
|
||||
pauseOnFocusLoss={false}
|
||||
draggable={false}
|
||||
theme={commonStore.settings.darkMode ? 'dark' : 'light'}
|
||||
/>
|
||||
<CustomToastContainer />
|
||||
</FluentProvider>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
"Stored Layers": "载入显存层数",
|
||||
"Precision": "精度",
|
||||
"Device": "设备",
|
||||
"Convert model with these configs": "用这些设置转换模型",
|
||||
"Convert model with these configs. Using a converted model will greatly improve the loading speed, but model parameters of the converted model cannot be modified.": "用这些设置转换模型. 使用转换过的模型能大大提升载入速度, 但是转换后的模型无法再修改模型参数.",
|
||||
"Manage Models": "管理模型",
|
||||
"Model": "模型",
|
||||
"Model Parameters": "模型参数",
|
||||
@@ -70,7 +70,7 @@
|
||||
"Type your message here": "在此输入消息",
|
||||
"Copy": "复制",
|
||||
"Read Aloud": "朗读",
|
||||
"Hello! I'm RWKV, an open-source and commercially available large language model.": "你好! 我是RWKV, 一个开源可商用的大语言模型.",
|
||||
"Hello! I'm RWKV, an open-source and commercially usable large language model.": "你好!我是RWKV,一个开源可商用的大语言模型。",
|
||||
"This tool's API is compatible with OpenAI API. It can be used with any ChatGPT tool you like. Go to the settings of some ChatGPT tool, replace the 'https://api.openai.com' part in the API address with '": "本工具的API与OpenAI API兼容. 因此可以配合任意你喜欢的ChatGPT工具使用. 打开某个ChatGPT工具的设置, 将API地址中的'https://api.openai.com'部分替换为'",
|
||||
"New Version Available": "新版本可用",
|
||||
"Update": "更新",
|
||||
@@ -78,16 +78,17 @@
|
||||
"Update Error": "更新出错",
|
||||
"Open the following URL with your browser to view the API documentation": "使用浏览器打开以下地址查看API文档",
|
||||
"By default, the maximum number of tokens that can be answered in a single response, it can be changed by the user by specifying API parameters.": "默认情况下, 单个回复最多回答的token数目, 用户可以通过自行指定API参数改变这个值",
|
||||
"Sampling temperature, the higher the stronger the randomness and creativity, while the lower, the more focused and deterministic it will be.": "采样温度, 越大随机性越强, 更具创造力, 越小则越保守稳定",
|
||||
"Consider the results of the top n% probability mass, 0.1 considers the top 10%, with higher quality but more conservative, 1 considers all results, with lower quality but more diverse.": "考虑前 n% 概率质量的结果, 0.1 考虑前 10%, 质量更高, 但更保守, 1 考虑所有质量结果, 质量降低, 但更多样",
|
||||
"Sampling temperature, it's like giving alcohol to a model, the higher the stronger the randomness and creativity, while the lower, the more focused and deterministic it will be.": "采样温度, 就像给模型喝酒, 越大随机性越强, 更具创造力, 越小则越保守稳定",
|
||||
"Just like feeding sedatives to the model. Consider the results of the top n% probability mass, 0.1 considers the top 10%, with higher quality but more conservative, 1 considers all results, with lower quality but more diverse.": "就像给模型喂镇静剂. 考虑前 n% 概率质量的结果, 0.1 考虑前 10%, 质量更高, 但更保守, 1 考虑所有质量结果, 质量降低, 但更多样",
|
||||
"Positive values penalize new tokens based on whether they appear in the text so far, increasing the model's likelihood to talk about new topics.": "存在惩罚. 正值根据新token在至今的文本中是否出现过, 来对其进行惩罚, 从而增加了模型涉及新话题的可能性",
|
||||
"Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model's likelihood to repeat the same line verbatim.": "频率惩罚. 正值根据新token在至今的文本中出现的频率/次数, 来对其进行惩罚, 从而减少模型原封不动地重复相同句子的可能性",
|
||||
"int8 uses less VRAM, but has slightly lower quality. fp16 has higher quality, and fp32 has the best quality.": "int8占用显存更低, 但质量略微下降. fp16质量更好, fp32质量最好",
|
||||
"Number of the neural network layers loaded into VRAM, the more you load, the faster the speed, but it consumes more VRAM.": "载入显存的神经网络层数, 载入越多, 速度越快, 但显存消耗越大",
|
||||
"Number of the neural network layers loaded into VRAM, the more you load, the faster the speed, but it consumes more VRAM. (If your VRAM is not enough, it will fail to load)": "载入显存的神经网络层数, 载入越多, 速度越快, 但显存消耗越大 (如果你的显存不够, 会载入失败)",
|
||||
"Whether to use CPU to calculate the last output layer of the neural network with FP32 precision to obtain better quality.": "是否使用cpu以fp32精度计算神经网络的最后一层输出层, 以获得更好的质量",
|
||||
"Downloads": "下载",
|
||||
"Pause": "暂停",
|
||||
"Continue": "继续",
|
||||
"Resume": "继续",
|
||||
"Check": "查看",
|
||||
"Model file not found": "模型文件不存在",
|
||||
"Can not find download url": "找不到下载地址",
|
||||
@@ -99,7 +100,7 @@
|
||||
"Model Config Exception": "模型配置异常",
|
||||
"Use Gitee Updates Source": "使用Gitee更新源",
|
||||
"Use Custom CUDA kernel to Accelerate": "使用自定义CUDA算子加速",
|
||||
"Enabling this option can greatly improve inference speed, but there may be compatibility issues. If it fails to start, please turn off this option.": "开启这个选项能大大提升推理速度,但可能存在兼容性问题,如果启动失败,请关闭此选项",
|
||||
"Enabling this option can greatly improve inference speed and save some VRAM, but there may be compatibility issues. If it fails to start, please turn off this option.": "开启这个选项能大大提升推理速度并节省显存,但可能存在兼容性问题,如果启动失败,请关闭此选项",
|
||||
"Supported custom cuda file not found": "没有找到支持的自定义cuda文件",
|
||||
"Failed to copy custom cuda file": "自定义cuda文件复制失败",
|
||||
"Downloading update, please wait. If it is not completed, please manually download the program from GitHub and replace the original program.": "正在下载更新,请等待。如果一直未完成,请从Github手动下载并覆盖原程序",
|
||||
@@ -114,7 +115,123 @@
|
||||
"Catgirl": "猫娘",
|
||||
"Explain Code": "代码解释",
|
||||
"Werewolf": "狼人杀",
|
||||
"Instruction": "指令",
|
||||
"Blank": "空白",
|
||||
"The following is an epic science fiction masterpiece that is immortalized, with delicate descriptions and grand depictions of interstellar civilization wars.\nChapter 1.\n": "以下是不朽的科幻史诗巨著,描写细腻,刻画了宏大的星际文明战争。\n第一章\n",
|
||||
"API Host": "API主机"
|
||||
"The following is an epic science fiction masterpiece that is immortalized, with delicate descriptions and grand depictions of interstellar civilization wars.\nChapter 1.\n": "《背影》\n我与父亲不相见已二年余了,我最不能忘记的是他的背影。\n那年冬天,祖母死了,父亲的差使也交卸了,正是祸不单行的日子。我从北京到徐州,打算",
|
||||
"The following is a conversation between a cat girl and her owner. The cat girl is a humanized creature that behaves like a cat but is humanoid. At the end of each sentence in the dialogue, she will add \"Meow~\". In the following content, Bob represents the owner and Alice represents the cat girl.\n\nBob: Hello.\n\nAlice: I'm here, meow~.\n\nBob: Can you tell jokes?": "以下是一位猫娘的主人和猫娘的对话内容,猫娘是一种拟人化的生物,其行为似猫但类人,在每一句对话末尾都会加上\"喵~\"。以下内容中,Bob代表主人,Alice代表猫娘。\n\nBob: 你好\n\nAlice: 主人我在哦,喵~\n\nBob: 你会讲笑话吗?",
|
||||
"When response finished, inject this content.": "响应结束时,插入此内容到末尾",
|
||||
"Inject start text": "起始注入文本",
|
||||
"Inject end text": "结尾注入文本",
|
||||
"Before the response starts, inject this content.": "响应开始前,在开头插入此内容",
|
||||
"There is currently a game of Werewolf with six players, including a Seer (who can check identities at night), two Werewolves (who can choose someone to kill at night), a Bodyguard (who can choose someone to protect at night), two Villagers (with no special abilities), and a game host. Bob will play as Player 1, Alice will play as Players 2-6 and the game host, and they will begin playing together. Every night, the host will ask Bob for his action and simulate the actions of the other players. During the day, the host will oversee the voting process and ask Bob for his vote. \n\nAlice: Next, I will act as the game host and assign everyone their roles, including randomly assigning yours. Then, I will simulate the actions of Players 2-6 and let you know what happens each day. Based on your assigned role, you can tell me your actions and I will let you know the corresponding results each day.\n\nBob: Okay, I understand. Let's begin. Please assign me a role. Am I the Seer, Werewolf, Villager, or Bodyguard?\n\nAlice: You are the Seer. Now that night has fallen, please choose a player to check his identity.\n\nBob: Tonight, I want to check Player 2 and find out his role.": "现在有一场六人狼人杀游戏,包括一名预言家(可以在夜晚查验身份),两名狼人(可以在夜晚选择杀人),一名守卫(可以在夜晚选择要守护的人),两名平民(无技能),一名主持人,以下内容中Bob将扮演其中的1号玩家,Alice来扮演2-6号玩家,以及主持人,并开始与Bob进行游戏,主持人每晚都会询问Bob的行动,并模拟其他人的行动,在白天则要主持投票,并同样询问Bob投票对象,公布投票结果。\n\nAlice: 接下来,我将首先作为主持人进行角色分配,并给你赋予随机的角色,之后我将模拟2-6号玩家进行行动,告知你每天的动态,根据你被分配的角色,你可以回复我你做的行动,我会告诉你每天对应的结果\n\nBob: 好的,我明白了,那么开始吧。请先给我一个角色身份。我是预言家,狼人,平民,守卫中的哪一个呢?\n\nAlice: 你的身份是预言家。现在夜晚降临,请选择你要查验的玩家。\n\nBob: 今晚我要验2号玩家,他是什么身份?",
|
||||
"Writer, Translator, Role-playing": "写作,翻译,角色扮演",
|
||||
"Chinese Kongfu": "情境冒险",
|
||||
"Allow external access to the API (service must be restarted)": "允许外部访问API (必须重启服务)",
|
||||
"Custom": "自定义",
|
||||
"Reset All Configs": "重置所有配置",
|
||||
"Cancel": "取消",
|
||||
"Confirm": "确认",
|
||||
"Are you sure you want to reset all configs? This will obtain the latest preset configs, but will override your custom configs and cannot be undone.": "你确定要重置所有配置吗?这会获取最新的预设配置,但会覆盖你的自定义配置,并且无法撤销",
|
||||
"Advanced": "高级",
|
||||
"Custom Python Path": "自定义Python路径",
|
||||
"Custom Models Path": "自定义模型路径",
|
||||
"Microsoft Visual C++ Redistributable is not installed, would you like to download it?": "微软VC++组件未安装, 是否下载?",
|
||||
"File Path Cannot Contain Space": "文件路径不能包含空格",
|
||||
"Current Strategy": "当前Strategy",
|
||||
"MacOS is not yet supported for performing this operation, please do it manually.": "MacOS尚未支持此操作, 请手动执行",
|
||||
"Linux is not yet supported for performing this operation, please do it manually.": "Linux尚未支持此操作, 请手动执行",
|
||||
"On Linux system, you must manually install python dependencies.": "在Linux系统下, 你必须手动安装python依赖",
|
||||
"Update completed, please restart the program.": "更新完成, 请重启程序",
|
||||
"Are you sure you want to reset this page? It cannot be undone.": "你确定要重置本页吗?这无法撤销",
|
||||
"Model file download is not complete": "模型文件下载未完成",
|
||||
"Error": "错误",
|
||||
"Are you sure you want to clear the conversation? It cannot be undone.": "你确定要清空对话吗?这无法撤销",
|
||||
"Save": "保存",
|
||||
"Conversation Saved": "对话已保存",
|
||||
"Open": "打开",
|
||||
"DPI Scaling": "显示缩放",
|
||||
"Restart the app to apply DPI Scaling.": "重启应用以使显示缩放生效",
|
||||
"Restart": "重启",
|
||||
"API Chat Model Name": "API聊天模型名",
|
||||
"API Completion Model Name": "API补全模型名",
|
||||
"Localhost": "本地",
|
||||
"Retry": "重试",
|
||||
"Delete": "删除",
|
||||
"Edit": "编辑",
|
||||
"Memory is not enough, try to increase the virtual memory or use a smaller model.": "内存不足,尝试增加虚拟内存,或使用一个更小规模的模型",
|
||||
"Bad PyTorch version, please reinstall PyTorch with cuda.": "错误的PyTorch版本,请重新安装CUDA版本的PyTorch",
|
||||
"The model file is corrupted, please download again.": "模型文件损坏,请重新下载",
|
||||
"Found no NVIDIA driver, please install the latest driver.": "没有找到NVIDIA驱动,请安装最新驱动",
|
||||
"VRAM is not enough, please reduce stored layers or use a lower precision in Configs page.": "显存不足,请在配置页面减少载入显存层数,或使用更低的精度",
|
||||
"Failed to enable custom CUDA kernel, ninja is required to load C++ extensions. You may be using the CPU version of PyTorch, please reinstall PyTorch with CUDA. Or if you are using a custom Python interpreter, you must compile the CUDA kernel by yourself or disable Custom CUDA kernel acceleration.": "自定义CUDA算子开启失败,需要安装Ninja来读取C++扩展。你可能正在使用CPU版本的PyTorch,请重新安装CUDA版本的PyTorch。如果你正在使用自定义Python解释器,你必须自己编译CUDA算子或禁用自定义CUDA算子加速",
|
||||
"Presets": "预设",
|
||||
"Online": "在线",
|
||||
"english": "英文",
|
||||
"chinese": "中文",
|
||||
"default": "默认",
|
||||
"japanese": "日文",
|
||||
"New Preset": "新建预设",
|
||||
"Import": "导入",
|
||||
"Name": "名称",
|
||||
"Imported successfully": "导入成功",
|
||||
"Failed to import. Please copy a preset to the clipboard.": "导入失败。请复制一个预设到剪贴板",
|
||||
"Clipboard is empty.": "剪贴板没有内容",
|
||||
"Successfully copied to clipboard.": "成功复制到剪贴板",
|
||||
"Edit Messages": "编辑对话",
|
||||
"Go Back": "返回",
|
||||
"Description": "描述",
|
||||
"Avatar Url": "头像图片地址",
|
||||
"Welcome Message": "欢迎语",
|
||||
"Display Preset Messages": "显示预设中的对话",
|
||||
"Tag": "标签",
|
||||
"Activate": "激活",
|
||||
"New": "新建",
|
||||
"user": "用户",
|
||||
"assistant": "AI",
|
||||
"system": "系统",
|
||||
"Regenerate": "重新生成",
|
||||
"LoRA Finetune": "LoRA微调",
|
||||
"Command Stopped": "命令已终止",
|
||||
"Please convert data first.": "请先转换数据",
|
||||
"Ubuntu is not installed, do you want to install it?": "Ubuntu未安装,是否安装?",
|
||||
"Install Ubuntu": "安装Ubuntu",
|
||||
"Please install Ubuntu using Microsoft Store, after installation click the Open button in Microsoft Store and then click the Train button": "请用Microsoft Store安装Ubuntu,安装完成后,点击Microsoft Store界面的“打开”按钮,然后点击“训练”按钮",
|
||||
"WSL is not enabled, do you want to enable it?": "WSL未启用,是否启用?",
|
||||
"Enable WSL": "启用WSL",
|
||||
"After installation, please restart your computer to enable WSL": "安装完成后,请重启电脑以启用WSL",
|
||||
"Data Process": "数据处理",
|
||||
"Data Path": "数据路径",
|
||||
"Vocab Path": "词表路径",
|
||||
"Train Parameters": "训练参数",
|
||||
"Base Model": "基底模型",
|
||||
"LoRA Model": "LoRA模型",
|
||||
"Merge Model": "合并模型",
|
||||
"Devices": "显卡数量",
|
||||
"Gradient Checkpoint": "梯度检查点标志",
|
||||
"Context Length": "上下文长度",
|
||||
"Epoch Steps": "每轮训练步数",
|
||||
"Epoch Count": "训练轮次",
|
||||
"Epoch Begin": "起始轮次",
|
||||
"Epoch Save": "保存间隔轮次",
|
||||
"Learning Rate Init": "初始学习率",
|
||||
"Learning Rate Final": "最终学习率",
|
||||
"Micro Batch Size": "微批次大小",
|
||||
"Accumulate Gradient Batches": "梯度累积批次",
|
||||
"Warmup Steps": "学习率预热步数",
|
||||
"Pre-FFN": "前馈网络预处理",
|
||||
"None": "空",
|
||||
"Merge model successfully": "合并模型成功",
|
||||
"Convert Data successfully": "数据转换成功",
|
||||
"Please select a LoRA model": "请选择一个LoRA模型",
|
||||
"You are using sample data for training. For formal training, please make sure to create your own jsonl file.": "你正在使用示例数据训练,对于正式训练场合,请务必创建你自己的jsonl训练数据",
|
||||
"WSL is not running, please retry. If it keeps happening, it means you may be using an outdated version of WSL, run \"wsl --update\" to update.": "WSL没有运行,请重试。如果一直出现此错误,意味着你可能正在使用旧版本的WSL,请在cmd执行\"wsl --update\"以更新",
|
||||
"Memory is not enough, try to increase the virtual memory or use a smaller base model.": "内存不足,尝试增加虚拟内存,或使用一个更小规模的基底模型",
|
||||
"VRAM is not enough": "显存不足",
|
||||
"Training data is not enough, reduce context length or add more data for training": "训练数据不足,请减小上下文长度或增加训练数据",
|
||||
"You are using WSL 1 for training, please upgrade to WSL 2. e.g. Run \"wsl --set-version Ubuntu-22.04 2\"": "你正在使用WSL 1进行训练,请升级到WSL 2。例如,运行\"wsl --set-version Ubuntu-22.04 2\"",
|
||||
"Matched CUDA is not installed": "未安装匹配的CUDA",
|
||||
"Failed to convert data": "数据转换失败",
|
||||
"Failed to merge model": "合并模型失败",
|
||||
"The data path should be a directory or a file in jsonl format (more formats will be supported in the future).\n\nWhen you provide a directory path, all the txt files within that directory will be automatically converted into training data. This is commonly used for large-scale training in writing, code generation, or knowledge bases.\n\nThe jsonl format file can be referenced at https://github.com/Abel2076/json2binidx_tool/blob/main/sample.jsonl.\nYou can also write it similar to OpenAI's playground format, as shown in https://platform.openai.com/playground/p/default-chat.\nEven for multi-turn conversations, they must be written in a single line using `\\n` to indicate line breaks. If they are different dialogues or topics, they should be written in separate lines.": "数据路径必须是一个文件夹,或者jsonl格式文件 (未来会支持更多格式)\n\n当你填写的路径是一个文件夹时,该文件夹内的所有txt文件会被自动转换为训练数据,通常这用于大批量训练写作,代码生成或知识库\n\njsonl文件的格式参考 https://github.com/Abel2076/json2binidx_tool/blob/main/sample.jsonl\n你也可以仿照openai的playground编写,参考 https://platform.openai.com/playground/p/default-chat\n即使是多轮对话也必须写在一行,用`\\n`表示换行,如果是不同对话或主题,则另起一行",
|
||||
"Size mismatch for blocks. You are attempting to continue training from the LoRA model, but it does not match the base model. Please set LoRA model to None.": "尺寸不匹配块。你正在尝试从LoRA模型继续训练,但该LoRA模型与基底模型不匹配,请将LoRA模型设为空"
|
||||
}
|
||||
|
Before Width: | Height: | Size: 1.8 MiB After Width: | Height: | Size: 238 KiB |
BIN
frontend/src/assets/images/logo.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
frontend/src/assets/images/strategy.jpg
Normal file
|
After Width: | Height: | Size: 132 KiB |
BIN
frontend/src/assets/images/strategy_zh.jpg
Normal file
|
After Width: | Height: | Size: 115 KiB |
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
|
||||
import { ClipboardSetText } from '../../wailsjs/runtime';
|
||||
import { ToolTipButton } from './ToolTipButton';
|
||||
|
||||
export const CopyButton: FC<{ content: string }> = ({ content }) => {
|
||||
export const CopyButton: FC<{ content: string, showDelay?: number, }> = ({ content, showDelay = 0 }) => {
|
||||
const { t } = useTranslation();
|
||||
const [copied, setCopied] = useState(false);
|
||||
|
||||
@@ -19,7 +19,8 @@ export const CopyButton: FC<{ content: string }> = ({ content }) => {
|
||||
};
|
||||
|
||||
return (
|
||||
<ToolTipButton desc={t('Copy')} size="small" appearance="subtle" icon={copied ? <CheckIcon /> : <CopyIcon />}
|
||||
<ToolTipButton desc={t('Copy')} size="small" appearance="subtle" showDelay={showDelay}
|
||||
icon={copied ? <CheckIcon /> : <CopyIcon />}
|
||||
onClick={onClick} />
|
||||
);
|
||||
};
|
||||
|
||||
17
frontend/src/components/CustomToastContainer.tsx
Normal file
@@ -0,0 +1,17 @@
|
||||
import commonStore from '../stores/commonStore';
|
||||
import { ToastContainer } from 'react-toastify';
|
||||
|
||||
export const CustomToastContainer = () =>
|
||||
<ToastContainer
|
||||
style={{ width: '350px' }}
|
||||
position="top-center"
|
||||
autoClose={4000}
|
||||
pauseOnHover={true}
|
||||
hideProgressBar={true}
|
||||
newestOnTop={true}
|
||||
closeOnClick={false}
|
||||
rtl={false}
|
||||
pauseOnFocusLoss={false}
|
||||
draggable={false}
|
||||
theme={commonStore.settings.darkMode ? 'dark' : 'light'}
|
||||
/>;
|
||||
64
frontend/src/components/DialogButton.tsx
Normal file
@@ -0,0 +1,64 @@
|
||||
import { FC, ReactElement } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogBody,
|
||||
DialogContent,
|
||||
DialogSurface,
|
||||
DialogTitle,
|
||||
DialogTrigger
|
||||
} from '@fluentui/react-components';
|
||||
import { ToolTipButton } from './ToolTipButton';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import MarkdownRender from './MarkdownRender';
|
||||
|
||||
export const DialogButton: FC<{
|
||||
text?: string | null
|
||||
icon?: ReactElement,
|
||||
tooltip?: string | null,
|
||||
className?: string,
|
||||
title: string,
|
||||
contentText: string,
|
||||
markdown?: boolean,
|
||||
onConfirm?: () => void,
|
||||
size?: 'small' | 'medium' | 'large',
|
||||
shape?: 'rounded' | 'circular' | 'square',
|
||||
appearance?: 'secondary' | 'primary' | 'outline' | 'subtle' | 'transparent',
|
||||
}> = ({
|
||||
text, icon, tooltip, className, title, contentText, markdown,
|
||||
onConfirm, size, shape, appearance
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return <Dialog>
|
||||
<DialogTrigger disableButtonEnhancement>
|
||||
{tooltip ?
|
||||
<ToolTipButton className={className} desc={tooltip} text={text} icon={icon} size={size} shape={shape}
|
||||
appearance={appearance} /> :
|
||||
<Button className={className} icon={icon} size={size} shape={shape} appearance={appearance}>{text}</Button>
|
||||
}
|
||||
</DialogTrigger>
|
||||
<DialogSurface>
|
||||
<DialogBody>
|
||||
<DialogTitle>{title}</DialogTitle>
|
||||
<DialogContent>
|
||||
{
|
||||
markdown ?
|
||||
<MarkdownRender>{contentText}</MarkdownRender> :
|
||||
contentText
|
||||
}
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<DialogTrigger disableButtonEnhancement>
|
||||
<Button appearance="secondary">{t('Cancel')}</Button>
|
||||
</DialogTrigger>
|
||||
<DialogTrigger disableButtonEnhancement>
|
||||
<Button appearance="primary" onClick={onConfirm}>{t('Confirm')}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
</DialogActions>
|
||||
</DialogBody>
|
||||
</DialogSurface>
|
||||
</Dialog>;
|
||||
};
|
||||
@@ -5,17 +5,23 @@ import classnames from 'classnames';
|
||||
export const Labeled: FC<{
|
||||
label: string;
|
||||
desc?: string | null,
|
||||
descComponent?: ReactElement,
|
||||
content: ReactElement,
|
||||
flex?: boolean,
|
||||
spaceBetween?: boolean,
|
||||
breakline?: boolean
|
||||
breakline?: boolean,
|
||||
onMouseEnter?: () => void
|
||||
onMouseLeave?: () => void
|
||||
}> = ({
|
||||
label,
|
||||
desc,
|
||||
descComponent,
|
||||
content,
|
||||
flex,
|
||||
spaceBetween,
|
||||
breakline
|
||||
breakline,
|
||||
onMouseEnter,
|
||||
onMouseLeave
|
||||
}) => {
|
||||
return (
|
||||
<div className={classnames(
|
||||
@@ -24,11 +30,11 @@ export const Labeled: FC<{
|
||||
breakline ? 'flex-col' : '',
|
||||
spaceBetween && 'justify-between')
|
||||
}>
|
||||
{desc ?
|
||||
<Tooltip content={desc} showDelay={0} hideDelay={0} relationship="description">
|
||||
<Label>{label}</Label>
|
||||
{(desc || descComponent) ?
|
||||
<Tooltip content={descComponent ? descComponent : desc!} showDelay={0} hideDelay={0} relationship="description">
|
||||
<Label onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>{label}</Label>
|
||||
</Tooltip> :
|
||||
<Label>{label}</Label>
|
||||
<Label onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave}>{label}</Label>
|
||||
}
|
||||
{content}
|
||||
</div>
|
||||
|
||||
@@ -7,13 +7,28 @@ import { observer } from 'mobx-react-lite';
|
||||
|
||||
const synth = window.speechSynthesis;
|
||||
|
||||
export const ReadButton: FC<{ content: string }> = observer(({ content }) => {
|
||||
export const ReadButton: FC<{
|
||||
content: string,
|
||||
inSpeaking?: boolean,
|
||||
showDelay?: number,
|
||||
setSpeakingOuter?: (speaking: boolean) => void
|
||||
}> = observer(({
|
||||
content,
|
||||
inSpeaking = false,
|
||||
showDelay = 0,
|
||||
setSpeakingOuter
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [speaking, setSpeaking] = useState(false);
|
||||
const [speaking, setSpeaking] = useState(inSpeaking);
|
||||
let lang: string = commonStore.settings.language;
|
||||
if (lang === 'dev')
|
||||
lang = 'en';
|
||||
|
||||
const setSpeakingInner = (speaking: boolean) => {
|
||||
setSpeakingOuter?.(speaking);
|
||||
setSpeaking(speaking);
|
||||
};
|
||||
|
||||
const startSpeak = () => {
|
||||
synth.cancel();
|
||||
|
||||
@@ -31,22 +46,22 @@ export const ReadButton: FC<{ content: string }> = observer(({ content }) => {
|
||||
Object.assign(utterance, {
|
||||
rate: 1,
|
||||
volume: 1,
|
||||
onend: () => setSpeaking(false),
|
||||
onerror: () => setSpeaking(false),
|
||||
onend: () => setSpeakingInner(false),
|
||||
onerror: () => setSpeakingInner(false),
|
||||
voice: voice
|
||||
});
|
||||
|
||||
synth.speak(utterance);
|
||||
setSpeaking(true);
|
||||
setSpeakingInner(true);
|
||||
};
|
||||
|
||||
const stopSpeak = () => {
|
||||
synth.cancel();
|
||||
setSpeaking(false);
|
||||
setSpeakingInner(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<ToolTipButton desc={t('Read Aloud')} size="small" appearance="subtle"
|
||||
<ToolTipButton desc={t('Read Aloud')} size="small" appearance="subtle" showDelay={showDelay}
|
||||
icon={speaking ? <MuteIcon /> : <UnmuteIcon />}
|
||||
onClick={speaking ? stopSpeak : startSpeak} />
|
||||
);
|
||||
|
||||
18
frontend/src/components/ResetConfigsButton.tsx
Normal file
@@ -0,0 +1,18 @@
|
||||
import React, { FC } from 'react';
|
||||
import { DialogButton } from './DialogButton';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ArrowReset20Regular } from '@fluentui/react-icons';
|
||||
import commonStore from '../stores/commonStore';
|
||||
|
||||
import { defaultModelConfigs, defaultModelConfigsMac } from '../pages/defaultModelConfigs';
|
||||
|
||||
export const ResetConfigsButton: FC<{ afterConfirm?: () => void }> = ({ afterConfirm }) => {
|
||||
const { t } = useTranslation();
|
||||
return <DialogButton icon={<ArrowReset20Regular />} tooltip={t('Reset All Configs')} title={t('Reset All Configs')}
|
||||
contentText={t('Are you sure you want to reset all configs? This will obtain the latest preset configs, but will override your custom configs and cannot be undone.')}
|
||||
onConfirm={() => {
|
||||
commonStore.setModelConfigs(commonStore.platform != 'darwin' ? defaultModelConfigs : defaultModelConfigsMac, false);
|
||||
commonStore.setCurrentConfigIndex(0, true);
|
||||
afterConfirm?.();
|
||||
}} />;
|
||||
};
|
||||
@@ -1,19 +1,11 @@
|
||||
import React, { FC, MouseEventHandler, ReactElement } from 'react';
|
||||
import commonStore, { ModelStatus } from '../stores/commonStore';
|
||||
import {
|
||||
AddToDownloadList,
|
||||
CopyFile,
|
||||
DepCheck,
|
||||
FileExists,
|
||||
InstallPyDep,
|
||||
StartServer
|
||||
} from '../../wailsjs/go/backend_golang/App';
|
||||
import { AddToDownloadList, CopyFile, FileExists, StartServer } from '../../wailsjs/go/backend_golang/App';
|
||||
import { Button } from '@fluentui/react-components';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { exit, getStatus, readRoot, switchModel, updateConfig } from '../apis';
|
||||
import { toast } from 'react-toastify';
|
||||
import manifest from '../../../manifest.json';
|
||||
import { getStrategy, getSupportedCustomCudaFile, saveCache, toastWithButton } from '../utils';
|
||||
import { checkDependencies, getStrategy, getSupportedCustomCudaFile, toastWithButton } from '../utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ToolTipButton } from './ToolTipButton';
|
||||
import { Play16Regular, Stop16Regular } from '@fluentui/react-icons';
|
||||
@@ -43,56 +35,32 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
const navigate = useNavigate();
|
||||
|
||||
const onClickMainButton = async () => {
|
||||
if (commonStore.status.modelStatus === ModelStatus.Offline) {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Starting });
|
||||
if (commonStore.status.status === ModelStatus.Offline) {
|
||||
commonStore.setStatus({ status: ModelStatus.Starting });
|
||||
|
||||
const modelConfig = commonStore.getCurrentModelConfig();
|
||||
let modelName = '';
|
||||
let modelPath = '';
|
||||
if (modelConfig && modelConfig.modelParameters) {
|
||||
modelName = modelConfig.modelParameters.modelName;
|
||||
modelPath = `./${manifest.localModelDir}/${modelName}`;
|
||||
modelPath = `${commonStore.settings.customModelsPath}/${modelName}`;
|
||||
} else {
|
||||
toast(t('Model Config Exception'), { type: 'error' });
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!commonStore.depComplete) {
|
||||
let depErrorMsg = '';
|
||||
await DepCheck().catch((e) => {
|
||||
depErrorMsg = e.message || e;
|
||||
WindowShow();
|
||||
if (depErrorMsg === 'python zip not found') {
|
||||
toastWithButton(t('Python target not found, would you like to download it?'), t('Download'), () => {
|
||||
toastWithButton(`${t('Downloading')} Python`, t('Check'), () => {
|
||||
navigate({ pathname: '/downloads' });
|
||||
}, { autoClose: 3000 });
|
||||
AddToDownloadList('python-3.10.11-embed-amd64.zip', 'https://www.python.org/ftp/python/3.10.11/python-3.10.11-embed-amd64.zip');
|
||||
});
|
||||
} else if (depErrorMsg.includes('DepCheck Error')) {
|
||||
toastWithButton(t('Python dependencies are incomplete, would you like to install them?'), t('Install'), () => {
|
||||
InstallPyDep(commonStore.settings.cnMirror);
|
||||
setTimeout(WindowShow, 1000);
|
||||
});
|
||||
} else {
|
||||
toast(depErrorMsg, { type: 'error' });
|
||||
}
|
||||
});
|
||||
if (depErrorMsg) {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
return;
|
||||
}
|
||||
commonStore.setDepComplete(true);
|
||||
CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py');
|
||||
saveCache();
|
||||
}
|
||||
const ok = await checkDependencies(navigate);
|
||||
if (!ok)
|
||||
return;
|
||||
|
||||
if (!await FileExists(modelPath)) {
|
||||
toastWithButton(t('Model file not found'), t('Download'), () => {
|
||||
const downloadUrl = commonStore.modelSourceList.find(item => item.name === modelName)?.downloadUrl;
|
||||
const currentModelSource = commonStore.modelSourceList.find(item => item.name === modelName);
|
||||
|
||||
const showDownloadPrompt = (promptInfo: string, downloadName: string) => {
|
||||
toastWithButton(promptInfo, t('Download'), () => {
|
||||
const downloadUrl = currentModelSource?.downloadUrl;
|
||||
if (downloadUrl) {
|
||||
toastWithButton(`${t('Downloading')} ${modelName}`, t('Check'), () => {
|
||||
toastWithButton(`${t('Downloading')} ${downloadName}`, t('Check'), () => {
|
||||
navigate({ pathname: '/downloads' });
|
||||
},
|
||||
{ autoClose: 3000 });
|
||||
@@ -101,8 +69,15 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
toast(t('Can not find download url'), { type: 'error' });
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
if (!await FileExists(modelPath)) {
|
||||
showDownloadPrompt(t('Model file not found'), modelName);
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
return;
|
||||
} else if (!currentModelSource?.isComplete) {
|
||||
showDownloadPrompt(t('Model file download is not complete'), modelName);
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -110,7 +85,13 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
|
||||
await exit(1000).catch(() => {
|
||||
});
|
||||
StartServer(port, commonStore.settings.host);
|
||||
StartServer(commonStore.settings.customPythonPath, port, commonStore.settings.host !== '127.0.0.1' ? '0.0.0.0' : '127.0.0.1').catch((e) => {
|
||||
const errMsg = e.message || e;
|
||||
if (errMsg.includes('path contains space'))
|
||||
toast(`${t('Error')} - ${t('File Path Cannot Contain Space')}`, { type: 'error' });
|
||||
else
|
||||
toast(t('Error') + ' - ' + errMsg, { type: 'error' });
|
||||
});
|
||||
setTimeout(WindowShow, 1000);
|
||||
|
||||
let timeoutCount = 6;
|
||||
@@ -125,7 +106,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
if (status)
|
||||
commonStore.setStatus(status);
|
||||
});
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Loading });
|
||||
commonStore.setStatus({ status: ModelStatus.Loading });
|
||||
toast(t('Loading Model'), { type: 'info' });
|
||||
updateConfig({
|
||||
max_tokens: modelConfig.apiParameters.maxResponseToken,
|
||||
@@ -135,73 +116,94 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
frequency_penalty: modelConfig.apiParameters.frequencyPenalty
|
||||
});
|
||||
|
||||
const strategy = getStrategy(modelConfig);
|
||||
let customCudaFile = '';
|
||||
if (modelConfig.modelParameters.useCustomCuda) {
|
||||
customCudaFile = getSupportedCustomCudaFile();
|
||||
if (customCudaFile) {
|
||||
FileExists('./py310/Lib/site-packages/rwkv/model.py').then((exist) => {
|
||||
// defensive measure. As Python has already been launched, will only take effect the next time it runs.
|
||||
if (!exist) CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py');
|
||||
});
|
||||
await CopyFile(customCudaFile, './py310/Lib/site-packages/rwkv/wkv_cuda.pyd').catch(() => {
|
||||
customCudaFile = '';
|
||||
toast(t('Failed to copy custom cuda file'), { type: 'error' });
|
||||
});
|
||||
} else
|
||||
toast(t('Supported custom cuda file not found'), { type: 'warning' });
|
||||
if ((modelConfig.modelParameters.device === 'CUDA' || modelConfig.modelParameters.device === 'Custom')
|
||||
&& modelConfig.modelParameters.useCustomCuda && !strategy.includes('fp32')) {
|
||||
if (commonStore.platform === 'windows') {
|
||||
customCudaFile = getSupportedCustomCudaFile();
|
||||
if (customCudaFile) {
|
||||
FileExists('./py310/Lib/site-packages/rwkv/model.py').then((exist) => {
|
||||
// defensive measure. As Python has already been launched, will only take effect the next time it runs.
|
||||
if (!exist) CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py');
|
||||
});
|
||||
await CopyFile(customCudaFile, './py310/Lib/site-packages/rwkv/wkv_cuda.pyd').catch(() => {
|
||||
FileExists('./py310/Lib/site-packages/rwkv/wkv_cuda.pyd').then((exist) => {
|
||||
if (!exist) {
|
||||
customCudaFile = '';
|
||||
toast(t('Failed to copy custom cuda file'), { type: 'error' });
|
||||
}
|
||||
});
|
||||
});
|
||||
} else
|
||||
toast(t('Supported custom cuda file not found'), { type: 'warning' });
|
||||
} else {
|
||||
customCudaFile = 'any';
|
||||
}
|
||||
}
|
||||
|
||||
switchModel({
|
||||
model: `${manifest.localModelDir}/${modelConfig.modelParameters.modelName}`,
|
||||
strategy: getStrategy(modelConfig),
|
||||
model: modelPath,
|
||||
strategy: strategy,
|
||||
customCuda: customCudaFile !== ''
|
||||
}).then((r) => {
|
||||
}).then(async (r) => {
|
||||
if (r.ok) {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Working });
|
||||
commonStore.setStatus({ status: ModelStatus.Working });
|
||||
toastWithButton(t('Startup Completed'), t('Chat'), () => {
|
||||
navigate({ pathname: '/chat' });
|
||||
}, { type: 'success', autoClose: 3000 });
|
||||
} else if (r.status === 304) {
|
||||
toast(t('Loading Model'), { type: 'info' });
|
||||
} else {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
toast(t('Failed to switch model'), { type: 'error' });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
const error = await r.text();
|
||||
const errorsMap = {
|
||||
'not enough memory': 'Memory is not enough, try to increase the virtual memory or use a smaller model.',
|
||||
'not compiled with CUDA': 'Bad PyTorch version, please reinstall PyTorch with cuda.',
|
||||
'invalid header or archive is corrupted': 'The model file is corrupted, please download again.',
|
||||
'no NVIDIA driver': 'Found no NVIDIA driver, please install the latest driver.',
|
||||
'CUDA out of memory': 'VRAM is not enough, please reduce stored layers or use a lower precision in Configs page.',
|
||||
'Ninja is required to load C++ extensions': 'Failed to enable custom CUDA kernel, ninja is required to load C++ extensions. You may be using the CPU version of PyTorch, please reinstall PyTorch with CUDA. Or if you are using a custom Python interpreter, you must compile the CUDA kernel by yourself or disable Custom CUDA kernel acceleration.'
|
||||
};
|
||||
const matchedError = Object.entries(errorsMap).find(([key, _]) => error.includes(key));
|
||||
const message = matchedError ? t(matchedError[1]) : error;
|
||||
toast(t('Failed to switch model') + ' - ' + message, { autoClose: 5000, type: 'error' });
|
||||
}
|
||||
}).catch(() => {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
toast(t('Failed to switch model'), { type: 'error' });
|
||||
}).catch((e) => {
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
toast(t('Failed to switch model') + ' - ' + (e.message || e), { type: 'error' });
|
||||
});
|
||||
}
|
||||
}).catch(() => {
|
||||
if (timeoutCount <= 0) {
|
||||
clearInterval(intervalId);
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
}
|
||||
});
|
||||
|
||||
timeoutCount--;
|
||||
}, 1000);
|
||||
} else {
|
||||
commonStore.setStatus({ modelStatus: ModelStatus.Offline });
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
exit();
|
||||
}
|
||||
};
|
||||
|
||||
const onClick = async (e: any) => {
|
||||
if (commonStore.status.modelStatus === ModelStatus.Offline)
|
||||
if (commonStore.status.status === ModelStatus.Offline)
|
||||
await onClickRun?.(e);
|
||||
await onClickMainButton();
|
||||
};
|
||||
|
||||
return (iconMode ?
|
||||
<ToolTipButton disabled={commonStore.status.modelStatus === ModelStatus.Starting}
|
||||
icon={iconModeButtonIcon[commonStore.status.modelStatus]}
|
||||
desc={t(mainButtonText[commonStore.status.modelStatus])}
|
||||
<ToolTipButton disabled={commonStore.status.status === ModelStatus.Starting}
|
||||
icon={iconModeButtonIcon[commonStore.status.status]}
|
||||
desc={t(mainButtonText[commonStore.status.status])}
|
||||
size="small" onClick={onClick} />
|
||||
:
|
||||
<Button disabled={commonStore.status.modelStatus === ModelStatus.Starting} appearance="primary" size="large"
|
||||
<Button disabled={commonStore.status.status === ModelStatus.Starting} appearance="primary" size="large"
|
||||
onClick={onClick}>
|
||||
{t(mainButtonText[commonStore.status.modelStatus])}
|
||||
{t(mainButtonText[commonStore.status.status])}
|
||||
</Button>
|
||||
);
|
||||
});
|
||||
|
||||
@@ -1,29 +1,35 @@
|
||||
import React, { FC, MouseEventHandler, ReactElement } from 'react';
|
||||
import React, { CSSProperties, FC, MouseEventHandler, ReactElement } from 'react';
|
||||
import { Button, Tooltip } from '@fluentui/react-components';
|
||||
|
||||
export const ToolTipButton: FC<{
|
||||
text?: string | null,
|
||||
desc: string,
|
||||
icon?: ReactElement,
|
||||
className?: string,
|
||||
style?: CSSProperties,
|
||||
size?: 'small' | 'medium' | 'large',
|
||||
shape?: 'rounded' | 'circular' | 'square';
|
||||
appearance?: 'secondary' | 'primary' | 'outline' | 'subtle' | 'transparent';
|
||||
disabled?: boolean,
|
||||
onClick?: MouseEventHandler
|
||||
showDelay?: number,
|
||||
}> = ({
|
||||
text,
|
||||
desc,
|
||||
icon,
|
||||
className,
|
||||
style,
|
||||
size,
|
||||
shape,
|
||||
appearance,
|
||||
disabled,
|
||||
onClick
|
||||
onClick,
|
||||
showDelay = 0
|
||||
}) => {
|
||||
return (
|
||||
<Tooltip content={desc} showDelay={0} hideDelay={0} relationship="label">
|
||||
<Button disabled={disabled} icon={icon} onClick={onClick} size={size} shape={shape}
|
||||
appearance={appearance}>{text}</Button>
|
||||
<Tooltip content={desc} showDelay={showDelay} hideDelay={0} relationship="label">
|
||||
<Button style={style} className={className} disabled={disabled} icon={icon} onClick={onClick} size={size}
|
||||
shape={shape} appearance={appearance}>{text}</Button>
|
||||
</Tooltip>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -29,8 +29,8 @@ export const WorkHeader: FC = observer(() => {
|
||||
<div className="flex flex-col gap-1">
|
||||
<div className="flex justify-between items-center">
|
||||
<div className="flex items-center gap-2">
|
||||
<PresenceBadge status={badgeStatus[commonStore.status.modelStatus]} />
|
||||
<Text size={100}>{t('Model Status') + ': ' + t(statusText[commonStore.status.modelStatus])}</Text>
|
||||
<PresenceBadge status={badgeStatus[commonStore.status.status]} />
|
||||
<Text size={100}>{t('Model Status') + ': ' + t(statusText[commonStore.status.status])}</Text>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<ConfigSelector size="small" />
|
||||
|
||||
@@ -6,6 +6,7 @@ import App from './App';
|
||||
import { HashRouter } from 'react-router-dom';
|
||||
import { startup } from './startup';
|
||||
import './_locales/i18n-react';
|
||||
import { WindowShow } from '../wailsjs/runtime';
|
||||
|
||||
startup().then(() => {
|
||||
const container = document.getElementById('root');
|
||||
@@ -17,4 +18,7 @@ startup().then(() => {
|
||||
<App />
|
||||
</HashRouter>
|
||||
);
|
||||
|
||||
// force display the window
|
||||
WindowShow();
|
||||
});
|
||||
|
||||
@@ -1,24 +1,31 @@
|
||||
import React, { FC, useEffect, useRef, useState } from 'react';
|
||||
import React, { FC, useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Avatar, PresenceBadge, Textarea } from '@fluentui/react-components';
|
||||
import { Avatar, Button, Menu, MenuPopover, MenuTrigger, PresenceBadge, Textarea } from '@fluentui/react-components';
|
||||
import commonStore, { ModelStatus } from '../stores/commonStore';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import classnames from 'classnames';
|
||||
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
||||
import { ConversationPair, getConversationPairs, Record } from '../utils/get-conversation-pairs';
|
||||
import logo from '../../../build/appicon.png';
|
||||
import { KebabHorizontalIcon, PencilIcon, SyncIcon, TrashIcon } from '@primer/octicons-react';
|
||||
import logo from '../assets/images/logo.png';
|
||||
import MarkdownRender from '../components/MarkdownRender';
|
||||
import { ToolTipButton } from '../components/ToolTipButton';
|
||||
import { ArrowCircleUp28Regular, Delete28Regular, RecordStop28Regular } from '@fluentui/react-icons';
|
||||
import { ArrowCircleUp28Regular, Delete28Regular, RecordStop28Regular, Save28Regular } from '@fluentui/react-icons';
|
||||
import { CopyButton } from '../components/CopyButton';
|
||||
import { ReadButton } from '../components/ReadButton';
|
||||
import { toast } from 'react-toastify';
|
||||
import { WorkHeader } from '../components/WorkHeader';
|
||||
import { DialogButton } from '../components/DialogButton';
|
||||
import { OpenFileFolder, OpenSaveFileDialog } from '../../wailsjs/go/backend_golang/App';
|
||||
import { toastWithButton } from '../utils';
|
||||
import { PresetsButton } from './PresetsManager/PresetsButton';
|
||||
import { useMediaQuery } from 'usehooks-ts';
|
||||
|
||||
export const userName = 'M E';
|
||||
export const botName = 'A I';
|
||||
|
||||
export const welcomeUuid = 'welcome';
|
||||
|
||||
export enum MessageType {
|
||||
Normal,
|
||||
Error
|
||||
@@ -39,23 +46,151 @@ export type MessageItem = {
|
||||
done: boolean
|
||||
}
|
||||
|
||||
export type Conversations = {
|
||||
export type Conversation = {
|
||||
[uuid: string]: MessageItem
|
||||
}
|
||||
|
||||
export type Role = 'assistant' | 'user' | 'system';
|
||||
|
||||
export type ConversationMessage = {
|
||||
role: Role;
|
||||
content: string;
|
||||
}
|
||||
|
||||
let chatSseController: AbortController | null = null;
|
||||
|
||||
const MoreUtilsButton: FC<{ uuid: string, setEditing: (editing: boolean) => void }> = observer(({
|
||||
uuid,
|
||||
setEditing
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
const [speaking, setSpeaking] = useState(false);
|
||||
|
||||
const messageItem = commonStore.conversation[uuid];
|
||||
|
||||
return <Menu>
|
||||
<MenuTrigger disableButtonEnhancement>
|
||||
<Button icon={<KebabHorizontalIcon />} size="small" appearance="subtle" />
|
||||
</MenuTrigger>
|
||||
<MenuPopover style={{ minWidth: 0 }}>
|
||||
<CopyButton content={messageItem.content} showDelay={500} />
|
||||
<ReadButton content={messageItem.content} inSpeaking={speaking} showDelay={500} setSpeakingOuter={setSpeaking} />
|
||||
<ToolTipButton desc={t('Edit')} icon={<PencilIcon />} showDelay={500} size="small" appearance="subtle"
|
||||
onClick={() => {
|
||||
setEditing(true);
|
||||
}} />
|
||||
<ToolTipButton desc={t('Delete')} icon={<TrashIcon />} showDelay={500} size="small" appearance="subtle"
|
||||
onClick={() => {
|
||||
commonStore.conversationOrder.splice(commonStore.conversationOrder.indexOf(uuid), 1);
|
||||
delete commonStore.conversation[uuid];
|
||||
}} />
|
||||
</MenuPopover>
|
||||
</Menu>;
|
||||
});
|
||||
|
||||
const ChatMessageItem: FC<{
|
||||
uuid: string, onSubmit: (message: string | null, answerId: string | null,
|
||||
startUuid: string | null, endUuid: string | null, includeEndUuid: boolean) => void
|
||||
}> = observer(({ uuid, onSubmit }) => {
|
||||
const { t } = useTranslation();
|
||||
const [editing, setEditing] = useState(false);
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
const messageItem = commonStore.conversation[uuid];
|
||||
|
||||
console.log(uuid);
|
||||
|
||||
const setEditingInner = (editing: boolean) => {
|
||||
setEditing(editing);
|
||||
if (editing) {
|
||||
setTimeout(() => {
|
||||
const textarea = textareaRef.current;
|
||||
if (textarea) {
|
||||
textarea.focus();
|
||||
textarea.selectionStart = textarea.value.length;
|
||||
textarea.selectionEnd = textarea.value.length;
|
||||
textarea.style.height = textarea.scrollHeight + 'px';
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return <div
|
||||
className={classnames(
|
||||
'flex gap-2 mb-2 overflow-hidden',
|
||||
messageItem.side === 'left' ? 'flex-row' : 'flex-row-reverse'
|
||||
)}
|
||||
onMouseEnter={() => {
|
||||
const utils = document.getElementById('utils-' + uuid);
|
||||
if (utils) utils.classList.remove('invisible');
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
const utils = document.getElementById('utils-' + uuid);
|
||||
if (utils) utils.classList.add('invisible');
|
||||
}}
|
||||
>
|
||||
<Avatar
|
||||
color={messageItem.color}
|
||||
name={messageItem.sender}
|
||||
image={(commonStore.activePreset && messageItem.sender === botName) ? { src: commonStore.activePreset.avatarImg } : messageItem.avatarImg ? { src: messageItem.avatarImg } : undefined}
|
||||
/>
|
||||
<div
|
||||
className={classnames(
|
||||
'flex p-2 rounded-lg overflow-hidden',
|
||||
editing ? 'grow' : '',
|
||||
messageItem.side === 'left' ? 'bg-gray-200' : 'bg-blue-500',
|
||||
messageItem.side === 'left' ? 'text-gray-600' : 'text-white'
|
||||
)}
|
||||
>
|
||||
{!editing ?
|
||||
<MarkdownRender>{messageItem.content}</MarkdownRender> :
|
||||
<Textarea ref={textareaRef}
|
||||
className="grow"
|
||||
style={{ minWidth: 0 }}
|
||||
value={messageItem.content}
|
||||
onChange={(e) => {
|
||||
messageItem.content = e.target.value;
|
||||
}}
|
||||
onBlur={() => {
|
||||
setEditingInner(false);
|
||||
}} />}
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 items-start">
|
||||
<div className="grow" />
|
||||
{(messageItem.type === MessageType.Error || !messageItem.done) &&
|
||||
<PresenceBadge size="extra-small" status={
|
||||
messageItem.type === MessageType.Error ? 'busy' : 'away'
|
||||
} />
|
||||
}
|
||||
<div className="flex invisible" id={'utils-' + uuid}>
|
||||
{
|
||||
messageItem.sender === botName && uuid !== welcomeUuid &&
|
||||
<ToolTipButton desc={t('Retry')} size="small" appearance="subtle"
|
||||
icon={<SyncIcon />} onClick={() => {
|
||||
onSubmit(null, uuid, null, uuid, false);
|
||||
}} />
|
||||
}
|
||||
<ToolTipButton desc={t('Edit')} icon={<PencilIcon />} size="small" appearance="subtle"
|
||||
onClick={() => {
|
||||
setEditingInner(true);
|
||||
}} />
|
||||
<MoreUtilsButton uuid={uuid} setEditing={setEditingInner} />
|
||||
</div>
|
||||
</div>
|
||||
</div>;
|
||||
});
|
||||
|
||||
const ChatPanel: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
const [message, setMessage] = useState('');
|
||||
const bodyRef = useRef<HTMLDivElement>(null);
|
||||
const inputRef = useRef<HTMLTextAreaElement>(null);
|
||||
const mq = useMediaQuery('(min-width: 640px)');
|
||||
const port = commonStore.getCurrentModelConfig().apiParameters.apiPort;
|
||||
const sseControllerRef = useRef<AbortController | null>(null);
|
||||
|
||||
let lastMessageId: string;
|
||||
let generating: boolean = false;
|
||||
if (commonStore.conversationsOrder.length > 0) {
|
||||
lastMessageId = commonStore.conversationsOrder[commonStore.conversationsOrder.length - 1];
|
||||
const lastMessage = commonStore.conversations[lastMessageId];
|
||||
if (commonStore.conversationOrder.length > 0) {
|
||||
lastMessageId = commonStore.conversationOrder[commonStore.conversationOrder.length - 1];
|
||||
const lastMessage = commonStore.conversation[lastMessageId];
|
||||
if (lastMessage.sender === botName)
|
||||
generating = !lastMessage.done;
|
||||
}
|
||||
@@ -67,16 +202,16 @@ const ChatPanel: FC = observer(() => {
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (commonStore.conversationsOrder.length === 0) {
|
||||
commonStore.setConversationsOrder(['welcome']);
|
||||
commonStore.setConversations({
|
||||
'welcome': {
|
||||
if (commonStore.conversationOrder.length === 0) {
|
||||
commonStore.setConversationOrder([welcomeUuid]);
|
||||
commonStore.setConversation({
|
||||
[welcomeUuid]: {
|
||||
sender: botName,
|
||||
type: MessageType.Normal,
|
||||
color: 'colorful',
|
||||
avatarImg: logo,
|
||||
time: new Date().toISOString(),
|
||||
content: t('Hello! I\'m RWKV, an open-source and commercially available large language model.'),
|
||||
content: t('Hello! I\'m RWKV, an open-source and commercially usable large language model.'),
|
||||
side: 'left',
|
||||
done: true
|
||||
}
|
||||
@@ -93,49 +228,59 @@ const ChatPanel: FC = observer(() => {
|
||||
e.stopPropagation();
|
||||
if (e.type === 'click' || (e.keyCode === 13 && !e.shiftKey)) {
|
||||
e.preventDefault();
|
||||
if (commonStore.status.modelStatus === ModelStatus.Offline) {
|
||||
if (commonStore.status.status === ModelStatus.Offline && !commonStore.settings.apiUrl) {
|
||||
toast(t('Please click the button in the top right corner to start the model'), { type: 'warning' });
|
||||
return;
|
||||
}
|
||||
if (!message) return;
|
||||
onSubmit(message);
|
||||
setMessage('');
|
||||
if (!commonStore.currentInput) return;
|
||||
onSubmit(commonStore.currentInput);
|
||||
commonStore.setCurrentInput('');
|
||||
}
|
||||
};
|
||||
|
||||
const onSubmit = (message: string) => {
|
||||
const newId = uuid();
|
||||
commonStore.conversations[newId] = {
|
||||
sender: userName,
|
||||
type: MessageType.Normal,
|
||||
color: 'brand',
|
||||
time: new Date().toISOString(),
|
||||
content: message,
|
||||
side: 'right',
|
||||
done: true
|
||||
};
|
||||
commonStore.setConversations(commonStore.conversations);
|
||||
commonStore.conversationsOrder.push(newId);
|
||||
commonStore.setConversationsOrder(commonStore.conversationsOrder);
|
||||
// if message is not null, create a user message;
|
||||
// if answerId is not null, override the answer with new response;
|
||||
// if startUuid is null, start generating api body messages from first message;
|
||||
// if endUuid is null, generate api body messages until last message;
|
||||
const onSubmit = useCallback((message: string | null = null, answerId: string | null = null,
|
||||
startUuid: string | null = null, endUuid: string | null = null, includeEndUuid: boolean = false) => {
|
||||
if (message) {
|
||||
const newId = uuid();
|
||||
commonStore.conversation[newId] = {
|
||||
sender: userName,
|
||||
type: MessageType.Normal,
|
||||
color: 'brand',
|
||||
time: new Date().toISOString(),
|
||||
content: message,
|
||||
side: 'right',
|
||||
done: true
|
||||
};
|
||||
commonStore.setConversation(commonStore.conversation);
|
||||
commonStore.conversationOrder.push(newId);
|
||||
commonStore.setConversationOrder(commonStore.conversationOrder);
|
||||
}
|
||||
|
||||
const records: Record[] = [];
|
||||
commonStore.conversationsOrder.forEach((uuid, index) => {
|
||||
const conversation = commonStore.conversations[uuid];
|
||||
if (conversation.done && conversation.type === MessageType.Normal && conversation.sender === botName) {
|
||||
if (index > 0) {
|
||||
const questionId = commonStore.conversationsOrder[index - 1];
|
||||
const question = commonStore.conversations[questionId];
|
||||
if (question.done && question.type === MessageType.Normal && question.sender === userName) {
|
||||
records.push({ question: question.content, answer: conversation.content });
|
||||
}
|
||||
}
|
||||
let startIndex = startUuid ? commonStore.conversationOrder.indexOf(startUuid) : 0;
|
||||
let endIndex = endUuid ? (commonStore.conversationOrder.indexOf(endUuid) + (includeEndUuid ? 1 : 0)) : commonStore.conversationOrder.length;
|
||||
let targetRange = commonStore.conversationOrder.slice(startIndex, endIndex);
|
||||
|
||||
const messages: ConversationMessage[] = [];
|
||||
targetRange.forEach((uuid, index) => {
|
||||
if (uuid === welcomeUuid)
|
||||
return;
|
||||
const messageItem = commonStore.conversation[uuid];
|
||||
if (messageItem.done && messageItem.type === MessageType.Normal && messageItem.sender === userName) {
|
||||
messages.push({ role: 'user', content: messageItem.content });
|
||||
} else if (messageItem.done && messageItem.type === MessageType.Normal && messageItem.sender === botName) {
|
||||
messages.push({ role: 'assistant', content: messageItem.content });
|
||||
}
|
||||
});
|
||||
const messages = getConversationPairs(records, false);
|
||||
(messages as ConversationPair[]).push({ role: 'user', content: message });
|
||||
|
||||
const answerId = uuid();
|
||||
commonStore.conversations[answerId] = {
|
||||
if (answerId === null) {
|
||||
answerId = uuid();
|
||||
commonStore.conversationOrder.push(answerId);
|
||||
}
|
||||
commonStore.conversation[answerId] = {
|
||||
sender: botName,
|
||||
type: MessageType.Normal,
|
||||
color: 'colorful',
|
||||
@@ -145,33 +290,34 @@ const ChatPanel: FC = observer(() => {
|
||||
side: 'left',
|
||||
done: false
|
||||
};
|
||||
commonStore.setConversations(commonStore.conversations);
|
||||
commonStore.conversationsOrder.push(answerId);
|
||||
commonStore.setConversationsOrder(commonStore.conversationsOrder);
|
||||
commonStore.setConversation(commonStore.conversation);
|
||||
commonStore.setConversationOrder(commonStore.conversationOrder);
|
||||
setTimeout(scrollToBottom);
|
||||
let answer = '';
|
||||
sseControllerRef.current = new AbortController();
|
||||
fetchEventSource(`http://127.0.0.1:${port}/chat/completions`, // https://api.openai.com/v1/chat/completions || http://127.0.0.1:${port}/chat/completions
|
||||
chatSseController = new AbortController();
|
||||
fetchEventSource( // https://api.openai.com/v1/chat/completions || http://127.0.0.1:${port}/chat/completions
|
||||
commonStore.settings.apiUrl ?
|
||||
commonStore.settings.apiUrl + '/v1/chat/completions' :
|
||||
`http://127.0.0.1:${port}/chat/completions`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer sk-`
|
||||
Authorization: `Bearer ${commonStore.settings.apiKey}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
messages,
|
||||
stream: true,
|
||||
model: 'gpt-3.5-turbo'
|
||||
model: commonStore.settings.apiChatModelName // 'gpt-3.5-turbo'
|
||||
}),
|
||||
signal: sseControllerRef.current?.signal,
|
||||
signal: chatSseController?.signal,
|
||||
onmessage(e) {
|
||||
console.log('sse message', e);
|
||||
scrollToBottom();
|
||||
if (e.data === '[DONE]') {
|
||||
commonStore.conversations[answerId].done = true;
|
||||
commonStore.conversations[answerId].content = commonStore.conversations[answerId].content.trim();
|
||||
commonStore.setConversations(commonStore.conversations);
|
||||
commonStore.setConversationsOrder([...commonStore.conversationsOrder]);
|
||||
commonStore.conversation[answerId!].done = true;
|
||||
commonStore.conversation[answerId!].content = commonStore.conversation[answerId!].content.trim();
|
||||
commonStore.setConversation(commonStore.conversation);
|
||||
commonStore.setConversationOrder([...commonStore.conversationOrder]);
|
||||
return;
|
||||
}
|
||||
let data;
|
||||
@@ -183,109 +329,107 @@ const ChatPanel: FC = observer(() => {
|
||||
}
|
||||
if (data.choices && Array.isArray(data.choices) && data.choices.length > 0) {
|
||||
answer += data.choices[0]?.delta?.content || '';
|
||||
commonStore.conversations[answerId].content = answer;
|
||||
commonStore.setConversations(commonStore.conversations);
|
||||
commonStore.setConversationsOrder([...commonStore.conversationsOrder]);
|
||||
commonStore.conversation[answerId!].content = answer;
|
||||
commonStore.setConversation(commonStore.conversation);
|
||||
commonStore.setConversationOrder([...commonStore.conversationOrder]);
|
||||
}
|
||||
},
|
||||
async onopen(response) {
|
||||
if (response.status !== 200) {
|
||||
commonStore.conversation[answerId!].content += '\n[ERROR]\n```\n' + response.statusText + '\n' + (await response.text()) + '\n```';
|
||||
commonStore.setConversation(commonStore.conversation);
|
||||
commonStore.setConversationOrder([...commonStore.conversationOrder]);
|
||||
setTimeout(scrollToBottom);
|
||||
}
|
||||
},
|
||||
onclose() {
|
||||
console.log('Connection closed');
|
||||
},
|
||||
onerror(err) {
|
||||
commonStore.conversations[answerId].type = MessageType.Error;
|
||||
commonStore.conversations[answerId].done = true;
|
||||
commonStore.setConversations(commonStore.conversations);
|
||||
commonStore.setConversationsOrder([...commonStore.conversationsOrder]);
|
||||
commonStore.conversation[answerId!].type = MessageType.Error;
|
||||
commonStore.conversation[answerId!].done = true;
|
||||
err = err.message || err;
|
||||
if (err && !err.includes('ReadableStreamDefaultReader'))
|
||||
commonStore.conversation[answerId!].content += '\n[ERROR]\n```\n' + err + '\n```';
|
||||
commonStore.setConversation(commonStore.conversation);
|
||||
commonStore.setConversationOrder([...commonStore.conversationOrder]);
|
||||
setTimeout(scrollToBottom);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="flex flex-col w-full grow gap-4 pt-4 overflow-hidden">
|
||||
<div ref={bodyRef} className="grow overflow-y-scroll overflow-x-hidden pr-2">
|
||||
{commonStore.conversationsOrder.map((uuid, index) => {
|
||||
const conversation = commonStore.conversations[uuid];
|
||||
return <div
|
||||
key={uuid}
|
||||
className={classnames(
|
||||
'flex gap-2 mb-2 overflow-hidden',
|
||||
conversation.side === 'left' ? 'flex-row' : 'flex-row-reverse'
|
||||
)}
|
||||
onMouseEnter={() => {
|
||||
const utils = document.getElementById('utils-' + uuid);
|
||||
if (utils) utils.classList.remove('invisible');
|
||||
}}
|
||||
onMouseLeave={() => {
|
||||
const utils = document.getElementById('utils-' + uuid);
|
||||
if (utils) utils.classList.add('invisible');
|
||||
}}
|
||||
>
|
||||
<Avatar
|
||||
color={conversation.color}
|
||||
name={conversation.sender}
|
||||
image={conversation.avatarImg ? { src: conversation.avatarImg } : undefined}
|
||||
/>
|
||||
<div
|
||||
className={classnames(
|
||||
'p-2 rounded-lg overflow-hidden',
|
||||
conversation.side === 'left' ? 'bg-gray-200' : 'bg-blue-500',
|
||||
conversation.side === 'left' ? 'text-gray-600' : 'text-white'
|
||||
)}
|
||||
>
|
||||
<MarkdownRender>{conversation.content}</MarkdownRender>
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 items-start">
|
||||
<div className="grow" />
|
||||
{(conversation.type === MessageType.Error || !conversation.done) &&
|
||||
<PresenceBadge size="extra-small" status={
|
||||
conversation.type === MessageType.Error ? 'busy' : 'away'
|
||||
} />
|
||||
}
|
||||
<div className="flex invisible" id={'utils-' + uuid}>
|
||||
<ReadButton content={conversation.content} />
|
||||
<CopyButton content={conversation.content} />
|
||||
</div>
|
||||
</div>
|
||||
</div>;
|
||||
})}
|
||||
{commonStore.conversationOrder.map(uuid =>
|
||||
<ChatMessageItem key={uuid} uuid={uuid} onSubmit={onSubmit} />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex items-end gap-2">
|
||||
<ToolTipButton desc={t('Clear')}
|
||||
<div className={classnames('flex items-end', mq ? 'gap-2' : '')}>
|
||||
<PresetsButton tab="Chat" size={mq ? 'large' : 'small'} shape="circular" appearance="subtle" />
|
||||
<DialogButton tooltip={t('Clear')}
|
||||
icon={<Delete28Regular />}
|
||||
size="large" shape="circular" appearance="subtle"
|
||||
onClick={(e) => {
|
||||
size={mq ? 'large' : 'small'} shape="circular" appearance="subtle" title={t('Clear')}
|
||||
contentText={t('Are you sure you want to clear the conversation? It cannot be undone.')}
|
||||
onConfirm={() => {
|
||||
if (generating)
|
||||
sseControllerRef.current?.abort();
|
||||
commonStore.setConversations({});
|
||||
commonStore.setConversationsOrder([]);
|
||||
}}
|
||||
/>
|
||||
chatSseController?.abort();
|
||||
commonStore.setConversation({});
|
||||
commonStore.setConversationOrder([]);
|
||||
}} />
|
||||
<Textarea
|
||||
ref={inputRef}
|
||||
style={{ minWidth: 0 }}
|
||||
className="grow"
|
||||
resize="vertical"
|
||||
placeholder={t('Type your message here')!}
|
||||
value={message}
|
||||
onChange={(e) => setMessage(e.target.value)}
|
||||
value={commonStore.currentInput}
|
||||
onChange={(e) => commonStore.setCurrentInput(e.target.value)}
|
||||
onKeyDown={handleKeyDownOrClick}
|
||||
/>
|
||||
<ToolTipButton desc={generating ? t('Stop') : t('Send')}
|
||||
icon={generating ? <RecordStop28Regular /> : <ArrowCircleUp28Regular />}
|
||||
size="large" shape="circular" appearance="subtle"
|
||||
size={mq ? 'large' : 'small'} shape="circular" appearance="subtle"
|
||||
onClick={(e) => {
|
||||
if (generating) {
|
||||
sseControllerRef.current?.abort();
|
||||
chatSseController?.abort();
|
||||
if (lastMessageId) {
|
||||
commonStore.conversations[lastMessageId].type = MessageType.Error;
|
||||
commonStore.conversations[lastMessageId].done = true;
|
||||
commonStore.setConversations(commonStore.conversations);
|
||||
commonStore.setConversationsOrder([...commonStore.conversationsOrder]);
|
||||
commonStore.conversation[lastMessageId].type = MessageType.Error;
|
||||
commonStore.conversation[lastMessageId].done = true;
|
||||
commonStore.setConversation(commonStore.conversation);
|
||||
commonStore.setConversationOrder([...commonStore.conversationOrder]);
|
||||
}
|
||||
} else {
|
||||
handleKeyDownOrClick(e);
|
||||
}
|
||||
}} />
|
||||
<ToolTipButton desc={t('Save')}
|
||||
icon={<Save28Regular />}
|
||||
size={mq ? 'large' : 'small'} shape="circular" appearance="subtle"
|
||||
onClick={() => {
|
||||
let savedContent: string = '';
|
||||
const isWorldModel = commonStore.getCurrentModelConfig().modelParameters.modelName.toLowerCase().includes('world');
|
||||
const user = isWorldModel ? 'Question' : 'Bob';
|
||||
const bot = isWorldModel ? 'Answer' : 'Alice';
|
||||
commonStore.conversationOrder.forEach((uuid) => {
|
||||
if (uuid === welcomeUuid)
|
||||
return;
|
||||
const messageItem = commonStore.conversation[uuid];
|
||||
if (messageItem.type !== MessageType.Error) {
|
||||
savedContent += `${messageItem.sender === userName ? user : bot}: ${messageItem.content}\n\n`;
|
||||
}
|
||||
});
|
||||
|
||||
OpenSaveFileDialog('*.md', 'conversation.md', savedContent).then((path) => {
|
||||
if (path)
|
||||
toastWithButton(t('Conversation Saved'), t('Open'), () => {
|
||||
OpenFileFolder(path, false);
|
||||
});
|
||||
}).catch(e => {
|
||||
toast(t('Error') + ' - ' + (e.message || e), { type: 'error', autoClose: 2500 });
|
||||
});
|
||||
}} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@@ -9,8 +9,16 @@ import { ApiParameters } from './Configs';
|
||||
import commonStore, { ModelStatus } from '../stores/commonStore';
|
||||
import { fetchEventSource } from '@microsoft/fetch-event-source';
|
||||
import { toast } from 'react-toastify';
|
||||
import { DialogButton } from '../components/DialogButton';
|
||||
import { PresetsButton } from './PresetsManager/PresetsButton';
|
||||
import { ToolTipButton } from '../components/ToolTipButton';
|
||||
import { ArrowSync20Regular } from '@fluentui/react-icons';
|
||||
|
||||
export type CompletionParams = Omit<ApiParameters, 'apiPort'> & { stop: string }
|
||||
export type CompletionParams = Omit<ApiParameters, 'apiPort'> & {
|
||||
stop: string,
|
||||
injectStart: string,
|
||||
injectEnd: string
|
||||
};
|
||||
|
||||
export type CompletionPreset = {
|
||||
name: string,
|
||||
@@ -22,75 +30,115 @@ export const defaultPresets: CompletionPreset[] = [{
|
||||
name: 'Writer',
|
||||
prompt: 'The following is an epic science fiction masterpiece that is immortalized, with delicate descriptions and grand depictions of interstellar civilization wars.\nChapter 1.\n',
|
||||
params: {
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1,
|
||||
maxResponseToken: 500,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4,
|
||||
stop: ''
|
||||
stop: '\\n\\nBob',
|
||||
injectStart: '',
|
||||
injectEnd: ''
|
||||
}
|
||||
}, {
|
||||
name: 'Translator',
|
||||
prompt: '',
|
||||
prompt: 'Translate this into Chinese.\n\nEnglish: What rooms do you have available?',
|
||||
params: {
|
||||
maxResponseToken: 4100,
|
||||
maxResponseToken: 500,
|
||||
temperature: 1,
|
||||
topP: 0.5,
|
||||
topP: 0.3,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4,
|
||||
stop: ''
|
||||
stop: '\\nEnglish',
|
||||
injectStart: '\\nChinese: ',
|
||||
injectEnd: '\\nEnglish: '
|
||||
}
|
||||
}, {
|
||||
name: 'Catgirl',
|
||||
prompt: '',
|
||||
prompt: 'The following is a conversation between a cat girl and her owner. The cat girl is a humanized creature that behaves like a cat but is humanoid. At the end of each sentence in the dialogue, she will add \"Meow~\". In the following content, Bob represents the owner and Alice represents the cat girl.\n\nBob: Hello.\n\nAlice: I\'m here, meow~.\n\nBob: Can you tell jokes?',
|
||||
params: {
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1,
|
||||
maxResponseToken: 500,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4,
|
||||
stop: ''
|
||||
stop: '\\n\\nBob',
|
||||
injectStart: '\\n\\nAlice: ',
|
||||
injectEnd: '\\n\\nBob: '
|
||||
}
|
||||
}, {
|
||||
name: 'Explain Code',
|
||||
prompt: '',
|
||||
name: 'Chinese Kongfu',
|
||||
prompt: 'Bob: 请你扮演一个文本冒险游戏,我是游戏主角。这是一个玄幻修真世界,有四大门派。我输入我的行动,请你显示行动结果,并具体描述环境。我的第一个行动是“醒来”,请开始故事。',
|
||||
params: {
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4,
|
||||
stop: ''
|
||||
maxResponseToken: 500,
|
||||
temperature: 1.1,
|
||||
topP: 0.7,
|
||||
presencePenalty: 0.3,
|
||||
frequencyPenalty: 0.3,
|
||||
stop: '\\n\\nBob',
|
||||
injectStart: '\\n\\nAlice: ',
|
||||
injectEnd: '\\n\\nBob: '
|
||||
}
|
||||
}, {
|
||||
// }, {
|
||||
// name: 'Explain Code',
|
||||
// prompt: 'export async function startup() {\n FileExists(\'cache.json\').then((exists) => {\n if (exists)\n downloadProgramFiles();\n else {\n deleteDynamicProgramFiles().then(downloadProgramFiles);\n }\n });\n EventsOn(\'downloadList\', (data) => {\n if (data)\n commonStore.setDownloadList(data);\n });\n\n initCache().then(initRemoteText);\n\n await initConfig();\n\n if (commonStore.settings.autoUpdatesCheck) // depends on config settings\n checkUpdate();\n\n getStatus(1000).then(status => { // depends on config api port\n if (status)\n commonStore.setStatus(status);\n });\n}\n\n\"\"\"\nHere\'s what the above code is doing, explained in a concise way:\n',
|
||||
// params: {
|
||||
// maxResponseToken: 500,
|
||||
// temperature: 0.8,
|
||||
// topP: 0.7,
|
||||
// presencePenalty: 0.4,
|
||||
// frequencyPenalty: 0.4,
|
||||
// stop: '\\n\\n',
|
||||
// injectStart: '',
|
||||
// injectEnd: ''
|
||||
// }
|
||||
// }, {
|
||||
name: 'Werewolf',
|
||||
prompt: '',
|
||||
prompt: 'There is currently a game of Werewolf with six players, including a Seer (who can check identities at night), two Werewolves (who can choose someone to kill at night), a Bodyguard (who can choose someone to protect at night), two Villagers (with no special abilities), and a game host. Bob will play as Player 1, Alice will play as Players 2-6 and the game host, and they will begin playing together. Every night, the host will ask Bob for his action and simulate the actions of the other players. During the day, the host will oversee the voting process and ask Bob for his vote. \n\nAlice: Next, I will act as the game host and assign everyone their roles, including randomly assigning yours. Then, I will simulate the actions of Players 2-6 and let you know what happens each day. Based on your assigned role, you can tell me your actions and I will let you know the corresponding results each day.\n\nBob: Okay, I understand. Let\'s begin. Please assign me a role. Am I the Seer, Werewolf, Villager, or Bodyguard?\n\nAlice: You are the Seer. Now that night has fallen, please choose a player to check his identity.\n\nBob: Tonight, I want to check Player 2 and find out his role.',
|
||||
params: {
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1,
|
||||
maxResponseToken: 500,
|
||||
temperature: 1.2,
|
||||
topP: 0.4,
|
||||
presencePenalty: 0.5,
|
||||
frequencyPenalty: 0.5,
|
||||
stop: '\\n\\nBob',
|
||||
injectStart: '\\n\\nAlice: ',
|
||||
injectEnd: '\\n\\nBob: '
|
||||
}
|
||||
}, {
|
||||
name: 'Instruction',
|
||||
prompt: 'Below is an instruction that describes a task. Write a response that appropriately completes the request.\n\n# Instruction:\nWrite a story using the following information\n\n# Input:\nA man named Alex chops a tree down\n\n# Response:\n',
|
||||
params: {
|
||||
maxResponseToken: 500,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4,
|
||||
stop: ''
|
||||
stop: '',
|
||||
injectStart: '',
|
||||
injectEnd: ''
|
||||
}
|
||||
}, {
|
||||
name: 'Blank',
|
||||
prompt: '',
|
||||
params: {
|
||||
maxResponseToken: 4100,
|
||||
maxResponseToken: 500,
|
||||
temperature: 1,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4,
|
||||
stop: ''
|
||||
stop: '',
|
||||
injectStart: '',
|
||||
injectEnd: ''
|
||||
}
|
||||
}];
|
||||
|
||||
let completionSseController: AbortController | null = null;
|
||||
|
||||
const CompletionPanel: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
const inputRef = useRef<HTMLTextAreaElement>(null);
|
||||
const port = commonStore.getCurrentModelConfig().apiParameters.apiPort;
|
||||
const sseControllerRef = useRef<AbortController | null>(null);
|
||||
|
||||
const scrollToBottom = () => {
|
||||
if (inputRef.current)
|
||||
@@ -104,6 +152,7 @@ const CompletionPanel: FC = observer(() => {
|
||||
}, []);
|
||||
|
||||
const setPreset = (preset: CompletionPreset) => {
|
||||
commonStore.setCompletionSubmittedPrompt(t(preset.prompt));
|
||||
commonStore.setCompletionPreset({
|
||||
...preset,
|
||||
prompt: t(preset.prompt)
|
||||
@@ -135,34 +184,41 @@ const CompletionPanel: FC = observer(() => {
|
||||
};
|
||||
|
||||
const onSubmit = (prompt: string) => {
|
||||
if (commonStore.status.modelStatus === ModelStatus.Offline) {
|
||||
commonStore.setCompletionSubmittedPrompt(prompt);
|
||||
|
||||
if (commonStore.status.status === ModelStatus.Offline && !commonStore.settings.apiUrl) {
|
||||
toast(t('Please click the button in the top right corner to start the model'), { type: 'warning' });
|
||||
commonStore.setCompletionGenerating(false);
|
||||
return;
|
||||
}
|
||||
|
||||
prompt += params.injectStart.replaceAll('\\n', '\n');
|
||||
|
||||
let answer = '';
|
||||
sseControllerRef.current = new AbortController();
|
||||
fetchEventSource(`http://127.0.0.1:${port}/completions`, // https://api.openai.com/v1/completions || http://127.0.0.1:${port}/completions
|
||||
completionSseController = new AbortController();
|
||||
fetchEventSource( // https://api.openai.com/v1/completions || http://127.0.0.1:${port}/completions
|
||||
commonStore.settings.apiUrl ?
|
||||
commonStore.settings.apiUrl + '/v1/completions' :
|
||||
`http://127.0.0.1:${port}/completions`,
|
||||
{
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Authorization: `Bearer sk-`
|
||||
Authorization: `Bearer ${commonStore.settings.apiKey}`
|
||||
},
|
||||
body: JSON.stringify({
|
||||
prompt,
|
||||
stream: true,
|
||||
model: 'text-davinci-003',
|
||||
model: commonStore.settings.apiCompletionModelName, // 'text-davinci-003'
|
||||
max_tokens: params.maxResponseToken,
|
||||
temperature: params.temperature,
|
||||
top_p: params.topP,
|
||||
presence_penalty: params.presencePenalty,
|
||||
frequency_penalty: params.frequencyPenalty,
|
||||
stop: params.stop || undefined
|
||||
stop: params.stop.replaceAll('\\n', '\n') || undefined
|
||||
}),
|
||||
signal: sseControllerRef.current?.signal,
|
||||
signal: completionSseController?.signal,
|
||||
onmessage(e) {
|
||||
console.log('sse message', e);
|
||||
scrollToBottom();
|
||||
if (e.data === '[DONE]') {
|
||||
commonStore.setCompletionGenerating(false);
|
||||
@@ -177,13 +233,25 @@ const CompletionPanel: FC = observer(() => {
|
||||
}
|
||||
if (data.choices && Array.isArray(data.choices) && data.choices.length > 0) {
|
||||
answer += data.choices[0].text;
|
||||
setPrompt(prompt + answer);
|
||||
setPrompt(prompt + answer.trim() + params.injectEnd.replaceAll('\\n', '\n'));
|
||||
}
|
||||
},
|
||||
async onopen(response) {
|
||||
if (response.status !== 200) {
|
||||
toast(response.statusText + '\n' + (await response.text()), {
|
||||
type: 'error'
|
||||
});
|
||||
}
|
||||
},
|
||||
onclose() {
|
||||
console.log('Connection closed');
|
||||
},
|
||||
onerror(err) {
|
||||
err = err.message || err;
|
||||
if (err && !err.includes('ReadableStreamDefaultReader'))
|
||||
toast(err, {
|
||||
type: 'error'
|
||||
});
|
||||
commonStore.setCompletionGenerating(false);
|
||||
throw err;
|
||||
}
|
||||
@@ -196,23 +264,30 @@ const CompletionPanel: FC = observer(() => {
|
||||
ref={inputRef}
|
||||
className="grow"
|
||||
value={prompt}
|
||||
onChange={(e) => setPrompt(e.target.value)}
|
||||
onChange={(e) => {
|
||||
commonStore.setCompletionSubmittedPrompt(e.target.value);
|
||||
setPrompt(e.target.value);
|
||||
}}
|
||||
/>
|
||||
<div className="flex flex-col gap-1 max-h-48 sm:max-w-sm sm:max-h-full">
|
||||
<Dropdown style={{ minWidth: 0 }}
|
||||
value={t(commonStore.completionPreset!.name)!}
|
||||
selectedOptions={[commonStore.completionPreset!.name]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue) {
|
||||
setPreset(defaultPresets.find((preset) => preset.name === data.optionValue)!);
|
||||
<div className="flex gap-2">
|
||||
<Dropdown style={{ minWidth: 0 }}
|
||||
className="grow"
|
||||
value={t(commonStore.completionPreset!.name)!}
|
||||
selectedOptions={[commonStore.completionPreset!.name]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue) {
|
||||
setPreset(defaultPresets.find((preset) => preset.name === data.optionValue)!);
|
||||
}
|
||||
}}>
|
||||
{
|
||||
defaultPresets.map((preset) =>
|
||||
<Option key={preset.name} value={preset.name}>{t(preset.name)!}</Option>)
|
||||
}
|
||||
}}>
|
||||
{
|
||||
defaultPresets.map((preset) =>
|
||||
<Option key={preset.name} value={preset.name}>{t(preset.name)!}</Option>)
|
||||
}
|
||||
</Dropdown>
|
||||
<div className="flex flex-col gap-1 overflow-x-hidden overflow-y-auto">
|
||||
</Dropdown>
|
||||
<PresetsButton tab="Completion" />
|
||||
</div>
|
||||
<div className="flex flex-col gap-1 overflow-x-hidden overflow-y-auto p-1">
|
||||
<Labeled flex breakline label={t('Max Response Token')}
|
||||
desc={t('By default, the maximum number of tokens that can be answered in a single response, it can be changed by the user by specifying API parameters.')}
|
||||
content={
|
||||
@@ -226,7 +301,7 @@ const CompletionPanel: FC = observer(() => {
|
||||
}} />
|
||||
} />
|
||||
<Labeled flex breakline label={t('Temperature')}
|
||||
desc={t('Sampling temperature, the higher the stronger the randomness and creativity, while the lower, the more focused and deterministic it will be.')}
|
||||
desc={t('Sampling temperature, it\'s like giving alcohol to a model, the higher the stronger the randomness and creativity, while the lower, the more focused and deterministic it will be.')}
|
||||
content={
|
||||
<ValuedSlider value={params.temperature} min={0} max={2} step={0.1}
|
||||
input
|
||||
@@ -237,7 +312,7 @@ const CompletionPanel: FC = observer(() => {
|
||||
}} />
|
||||
} />
|
||||
<Labeled flex breakline label={t('Top_P')}
|
||||
desc={t('Consider the results of the top n% probability mass, 0.1 considers the top 10%, with higher quality but more conservative, 1 considers all results, with lower quality but more diverse.')}
|
||||
desc={t('Just like feeding sedatives to the model. Consider the results of the top n% probability mass, 0.1 considers the top 10%, with higher quality but more conservative, 1 considers all results, with lower quality but more diverse.')}
|
||||
content={
|
||||
<ValuedSlider value={params.topP} min={0} max={1} step={0.1} input
|
||||
onChange={(e, data) => {
|
||||
@@ -249,7 +324,7 @@ const CompletionPanel: FC = observer(() => {
|
||||
<Labeled flex breakline label={t('Presence Penalty')}
|
||||
desc={t('Positive values penalize new tokens based on whether they appear in the text so far, increasing the model\'s likelihood to talk about new topics.')}
|
||||
content={
|
||||
<ValuedSlider value={params.presencePenalty} min={-2} max={2}
|
||||
<ValuedSlider value={params.presencePenalty} min={0} max={2}
|
||||
step={0.1} input
|
||||
onChange={(e, data) => {
|
||||
setParams({
|
||||
@@ -260,7 +335,7 @@ const CompletionPanel: FC = observer(() => {
|
||||
<Labeled flex breakline label={t('Frequency Penalty')}
|
||||
desc={t('Positive values penalize new tokens based on their existing frequency in the text so far, decreasing the model\'s likelihood to repeat the same line verbatim.')}
|
||||
content={
|
||||
<ValuedSlider value={params.frequencyPenalty} min={-2} max={2}
|
||||
<ValuedSlider value={params.frequencyPenalty} min={0} max={2}
|
||||
step={0.1} input
|
||||
onChange={(e, data) => {
|
||||
setParams({
|
||||
@@ -278,15 +353,43 @@ const CompletionPanel: FC = observer(() => {
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled flex breakline label={t('Inject start text')}
|
||||
desc={t('Before the response starts, inject this content.')}
|
||||
content={
|
||||
<Input value={params.injectStart}
|
||||
onChange={(e, data) => {
|
||||
setParams({
|
||||
injectStart: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled flex breakline label={t('Inject end text')}
|
||||
desc={t('When response finished, inject this content.')}
|
||||
content={
|
||||
<Input value={params.injectEnd}
|
||||
onChange={(e, data) => {
|
||||
setParams({
|
||||
injectEnd: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
</div>
|
||||
<div className="grow" />
|
||||
<div className="flex justify-between gap-2">
|
||||
<Button className="grow" onClick={() => {
|
||||
setPreset(defaultPresets.find((preset) => preset.name === name)!);
|
||||
}}>{t('Reset')}</Button>
|
||||
<ToolTipButton desc={t('Regenerate')} icon={<ArrowSync20Regular />} onClick={() => {
|
||||
completionSseController?.abort();
|
||||
commonStore.setCompletionGenerating(true);
|
||||
setPrompt(commonStore.completionSubmittedPrompt);
|
||||
onSubmit(commonStore.completionSubmittedPrompt);
|
||||
}} />
|
||||
<DialogButton className="grow" text={t('Reset')} title={t('Reset')}
|
||||
contentText={t('Are you sure you want to reset this page? It cannot be undone.')}
|
||||
onConfirm={() => {
|
||||
setPreset(defaultPresets.find((preset) => preset.name === name)!);
|
||||
}} />
|
||||
<Button className="grow" appearance="primary" onClick={() => {
|
||||
if (commonStore.completionGenerating) {
|
||||
sseControllerRef.current?.abort();
|
||||
completionSseController?.abort();
|
||||
commonStore.setCompletionGenerating(false);
|
||||
} else {
|
||||
commonStore.setCompletionGenerating(true);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Dropdown, Input, Label, Option, Select, Switch } from '@fluentui/react-components';
|
||||
import { Dropdown, Input, Label, Option, Select, Switch, Text } from '@fluentui/react-components';
|
||||
import { AddCircle20Regular, DataUsageSettings20Regular, Delete20Regular, Save20Regular } from '@fluentui/react-icons';
|
||||
import React, { FC } from 'react';
|
||||
import { Section } from '../components/Section';
|
||||
@@ -13,11 +13,13 @@ import { Page } from '../components/Page';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { RunButton } from '../components/RunButton';
|
||||
import { updateConfig } from '../apis';
|
||||
import { ConvertModel, FileExists } from '../../wailsjs/go/backend_golang/App';
|
||||
import manifest from '../../../manifest.json';
|
||||
import { getStrategy, refreshLocalModels } from '../utils';
|
||||
import { ConvertModel, FileExists, GetPyError } from '../../wailsjs/go/backend_golang/App';
|
||||
import { getStrategy } from '../utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { WindowShow } from '../../wailsjs/runtime/runtime';
|
||||
import strategyImg from '../assets/images/strategy.jpg';
|
||||
import strategyZhImg from '../assets/images/strategy_zh.jpg';
|
||||
import { ResetConfigsButton } from '../components/ResetConfigsButton';
|
||||
|
||||
export type ApiParameters = {
|
||||
apiPort: number
|
||||
@@ -28,7 +30,7 @@ export type ApiParameters = {
|
||||
frequencyPenalty: number;
|
||||
}
|
||||
|
||||
export type Device = 'CPU' | 'CUDA';
|
||||
export type Device = 'CPU' | 'CUDA' | 'MPS' | 'Custom';
|
||||
export type Precision = 'fp16' | 'int8' | 'fp32';
|
||||
|
||||
export type ModelParameters = {
|
||||
@@ -38,8 +40,8 @@ export type ModelParameters = {
|
||||
precision: Precision;
|
||||
storedLayers: number;
|
||||
maxStoredLayers: number;
|
||||
enableHighPrecisionForLastLayer: boolean;
|
||||
useCustomCuda?: boolean;
|
||||
customStrategy?: string;
|
||||
}
|
||||
|
||||
export type ModelConfig = {
|
||||
@@ -49,507 +51,11 @@ export type ModelConfig = {
|
||||
modelParameters: ModelParameters
|
||||
}
|
||||
|
||||
export const defaultModelConfigs: ModelConfig[] = [
|
||||
{
|
||||
name: 'GPU-2G-1B5-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-1B5-v12-Eng98%-Other2%-20230520-ctx4096.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 4,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-4G-1B5-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-1B5-v12-Eng98%-Other2%-20230520-ctx4096.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-4G-3B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-3B-v12-Eng98%-Other2%-20230520-ctx4096.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 24,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-4G-3B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-3B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230429-ctx4096.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 24,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-4G-7B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 8,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-4G-7B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230430-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 8,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-6G-1B5-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-1B5-v12-Eng98%-Other2%-20230520-ctx4096.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'fp16',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-6G-3B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-3B-v12-Eng98%-Other2%-20230520-ctx4096.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-6G-3B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-3B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230429-ctx4096.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-6G-7B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 18,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-6G-7B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230430-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 18,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: true
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-8G-3B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-3B-v12-Eng98%-Other2%-20230520-ctx4096.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'fp16',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-8G-3B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-3B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230429-ctx4096.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'fp16',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-10G-7B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-10G-7B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230430-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-12G-7B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'fp16',
|
||||
storedLayers: 22,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-12G-7B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230430-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'fp16',
|
||||
storedLayers: 22,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-16G-7B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'fp16',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-16G-7B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230430-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'fp16',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-18G-14B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-14B-v12-Eng98%-Other2%-20230523-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'int8',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'GPU-32G-14B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-14B-v12-Eng98%-Other2%-20230523-ctx8192.pth',
|
||||
device: 'CUDA',
|
||||
precision: 'fp16',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'CPU-6G-1B5-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-1B5-v12-Eng98%-Other2%-20230520-ctx4096.pth',
|
||||
device: 'CPU',
|
||||
precision: 'fp32',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'CPU-12G-3B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-3B-v12-Eng98%-Other2%-20230520-ctx4096.pth',
|
||||
device: 'CPU',
|
||||
precision: 'fp32',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'CPU-12G-3B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-3B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230429-ctx4096.pth',
|
||||
device: 'CPU',
|
||||
precision: 'fp32',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'CPU-28G-7B-EN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v12-Eng98%-Other2%-20230521-ctx8192.pth',
|
||||
device: 'CPU',
|
||||
precision: 'fp32',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'CPU-28G-7B-CN',
|
||||
apiParameters: {
|
||||
apiPort: 8000,
|
||||
maxResponseToken: 4100,
|
||||
temperature: 1.2,
|
||||
topP: 0.5,
|
||||
presencePenalty: 0.4,
|
||||
frequencyPenalty: 0.4
|
||||
},
|
||||
modelParameters: {
|
||||
modelName: 'RWKV-4-Raven-7B-v11-Eng49%-Chn49%-Jpn1%-Other1%-20230430-ctx8192.pth',
|
||||
device: 'CPU',
|
||||
precision: 'fp32',
|
||||
storedLayers: 41,
|
||||
maxStoredLayers: 41,
|
||||
enableHighPrecisionForLastLayer: false
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
export const Configs: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
const [selectedIndex, setSelectedIndex] = React.useState(commonStore.currentModelConfigIndex);
|
||||
const [selectedConfig, setSelectedConfig] = React.useState(commonStore.modelConfigs[selectedIndex]);
|
||||
const [displayStrategyImg, setDisplayStrategyImg] = React.useState(false);
|
||||
const navigate = useNavigate();
|
||||
const port = selectedConfig.apiParameters.apiPort;
|
||||
|
||||
@@ -618,6 +124,10 @@ export const Configs: FC = observer(() => {
|
||||
commonStore.deleteModelConfig(selectedIndex);
|
||||
updateSelectedIndex(Math.min(selectedIndex, commonStore.modelConfigs.length - 1));
|
||||
}} />
|
||||
<ResetConfigsButton afterConfirm={() => {
|
||||
setSelectedIndex(0);
|
||||
setSelectedConfig(commonStore.modelConfigs[0]);
|
||||
}} />
|
||||
<ToolTipButton desc={t('Save Config')} icon={<Save20Regular />} onClick={onClickSave} />
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
@@ -656,7 +166,7 @@ export const Configs: FC = observer(() => {
|
||||
}} />
|
||||
} />
|
||||
<Labeled label={t('Temperature') + ' *'}
|
||||
desc={t('Sampling temperature, the higher the stronger the randomness and creativity, while the lower, the more focused and deterministic it will be.')}
|
||||
desc={t('Sampling temperature, it\'s like giving alcohol to a model, the higher the stronger the randomness and creativity, while the lower, the more focused and deterministic it will be.')}
|
||||
content={
|
||||
<ValuedSlider value={selectedConfig.apiParameters.temperature} min={0} max={2} step={0.1}
|
||||
input
|
||||
@@ -667,7 +177,7 @@ export const Configs: FC = observer(() => {
|
||||
}} />
|
||||
} />
|
||||
<Labeled label={t('Top_P') + ' *'}
|
||||
desc={t('Consider the results of the top n% probability mass, 0.1 considers the top 10%, with higher quality but more conservative, 1 considers all results, with lower quality but more diverse.')}
|
||||
desc={t('Just like feeding sedatives to the model. Consider the results of the top n% probability mass, 0.1 considers the top 10%, with higher quality but more conservative, 1 considers all results, with lower quality but more diverse.')}
|
||||
content={
|
||||
<ValuedSlider value={selectedConfig.apiParameters.topP} min={0} max={1} step={0.1} input
|
||||
onChange={(e, data) => {
|
||||
@@ -714,8 +224,12 @@ export const Configs: FC = observer(() => {
|
||||
modelName: data.value
|
||||
});
|
||||
}}>
|
||||
{!commonStore.modelSourceList.find(item => item.name === selectedConfig.modelParameters.modelName)?.isComplete
|
||||
&& <option key={-1}
|
||||
value={selectedConfig.modelParameters.modelName}>{selectedConfig.modelParameters.modelName}
|
||||
</option>}
|
||||
{commonStore.modelSourceList.map((modelItem, index) =>
|
||||
modelItem.isLocal && <option key={index} value={modelItem.name}>{modelItem.name}</option>
|
||||
modelItem.isComplete && <option key={index} value={modelItem.name}>{modelItem.name}</option>
|
||||
)}
|
||||
</Select>
|
||||
<ToolTipButton desc={t('Manage Models')} icon={<DataUsageSettings20Regular />} onClick={() => {
|
||||
@@ -723,87 +237,134 @@ export const Configs: FC = observer(() => {
|
||||
}} />
|
||||
</div>
|
||||
} />
|
||||
<ToolTipButton text={t('Convert')} desc={t('Convert model with these configs')} onClick={async () => {
|
||||
const modelPath = `${manifest.localModelDir}/${selectedConfig.modelParameters.modelName}`;
|
||||
if (await FileExists(modelPath)) {
|
||||
const strategy = getStrategy(selectedConfig);
|
||||
const newModelPath = modelPath + '-' + strategy.replace(/[> *+]/g, '-');
|
||||
toast(t('Start Converting'), { autoClose: 1000, type: 'info' });
|
||||
ConvertModel(modelPath, strategy, newModelPath).then(() => {
|
||||
toast(`${t('Convert Success')} - ${newModelPath}`, { type: 'success' });
|
||||
refreshLocalModels({ models: commonStore.modelSourceList }, false);
|
||||
}).catch(e => {
|
||||
toast(`${t('Convert Failed')} - ${e.message || e}`, { type: 'error' });
|
||||
});
|
||||
setTimeout(WindowShow, 1000);
|
||||
} else {
|
||||
toast(`${t('Model Not Found')} - ${modelPath}`, { type: 'error' });
|
||||
}
|
||||
}} />
|
||||
<Labeled label={t('Device')} content={
|
||||
<Dropdown style={{ minWidth: 0 }} className="grow" value={selectedConfig.modelParameters.device}
|
||||
<ToolTipButton text={t('Convert')}
|
||||
desc={t('Convert model with these configs. Using a converted model will greatly improve the loading speed, but model parameters of the converted model cannot be modified.')}
|
||||
onClick={async () => {
|
||||
if (commonStore.platform == 'darwin') {
|
||||
toast(t('MacOS is not yet supported for performing this operation, please do it manually.'), { type: 'info' });
|
||||
return;
|
||||
} else if (commonStore.platform == 'linux') {
|
||||
toast(t('Linux is not yet supported for performing this operation, please do it manually.'), { type: 'info' });
|
||||
return;
|
||||
}
|
||||
|
||||
const modelPath = `${commonStore.settings.customModelsPath}/${selectedConfig.modelParameters.modelName}`;
|
||||
if (await FileExists(modelPath)) {
|
||||
const strategy = getStrategy(selectedConfig);
|
||||
const newModelPath = modelPath + '-' + strategy.replace(/[:> *+]/g, '-');
|
||||
toast(t('Start Converting'), { autoClose: 1000, type: 'info' });
|
||||
ConvertModel(commonStore.settings.customPythonPath, modelPath, strategy, newModelPath).then(async () => {
|
||||
if (!await FileExists(newModelPath)) {
|
||||
toast(t('Convert Failed') + ' - ' + await GetPyError(), { type: 'error' });
|
||||
} else {
|
||||
toast(`${t('Convert Success')} - ${newModelPath}`, { type: 'success' });
|
||||
}
|
||||
}).catch(e => {
|
||||
const errMsg = e.message || e;
|
||||
if (errMsg.includes('path contains space'))
|
||||
toast(`${t('Convert Failed')} - ${t('File Path Cannot Contain Space')}`, { type: 'error' });
|
||||
else
|
||||
toast(`${t('Convert Failed')} - ${e.message || e}`, { type: 'error' });
|
||||
});
|
||||
setTimeout(WindowShow, 1000);
|
||||
} else {
|
||||
toast(`${t('Model Not Found')} - ${modelPath}`, { type: 'error' });
|
||||
}
|
||||
}} />
|
||||
<Labeled label={t('Strategy')} content={
|
||||
<Dropdown style={{ minWidth: 0 }} className="grow" value={t(selectedConfig.modelParameters.device)!}
|
||||
selectedOptions={[selectedConfig.modelParameters.device]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionText) {
|
||||
if (data.optionValue) {
|
||||
setSelectedConfigModelParams({
|
||||
device: data.optionText as Device
|
||||
device: data.optionValue as Device
|
||||
});
|
||||
}
|
||||
}}>
|
||||
<Option>CPU</Option>
|
||||
<Option>CUDA</Option>
|
||||
<Option value="CPU">CPU</Option>
|
||||
{commonStore.platform === 'darwin' && <Option value="MPS">MPS</Option>}
|
||||
<Option value="CUDA">CUDA</Option>
|
||||
<Option value="Custom">{t('Custom')!}</Option>
|
||||
</Dropdown>
|
||||
} />
|
||||
<Labeled label={t('Precision')}
|
||||
desc={t('int8 uses less VRAM, but has slightly lower quality. fp16 has higher quality, and fp32 has the best quality.')}
|
||||
content={
|
||||
<Dropdown style={{ minWidth: 0 }} className="grow"
|
||||
value={selectedConfig.modelParameters.precision}
|
||||
selectedOptions={[selectedConfig.modelParameters.precision]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionText) {
|
||||
{
|
||||
selectedConfig.modelParameters.device != 'Custom' && <Labeled label={t('Precision')}
|
||||
desc={t('int8 uses less VRAM, but has slightly lower quality. fp16 has higher quality, and fp32 has the best quality.')}
|
||||
content={
|
||||
<Dropdown style={{ minWidth: 0 }} className="grow"
|
||||
value={selectedConfig.modelParameters.precision}
|
||||
selectedOptions={[selectedConfig.modelParameters.precision]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionText) {
|
||||
setSelectedConfigModelParams({
|
||||
precision: data.optionText as Precision
|
||||
});
|
||||
}
|
||||
}}>
|
||||
<Option>fp16</Option>
|
||||
<Option>int8</Option>
|
||||
<Option>fp32</Option>
|
||||
</Dropdown>
|
||||
} />
|
||||
}
|
||||
{
|
||||
selectedConfig.modelParameters.device == 'CUDA' &&
|
||||
<Labeled label={t('Current Strategy')}
|
||||
content={<Text> {getStrategy(selectedConfig)} </Text>} />
|
||||
}
|
||||
{
|
||||
selectedConfig.modelParameters.device == 'CUDA' &&
|
||||
<Labeled label={t('Stored Layers')}
|
||||
desc={t('Number of the neural network layers loaded into VRAM, the more you load, the faster the speed, but it consumes more VRAM. (If your VRAM is not enough, it will fail to load)')}
|
||||
content={
|
||||
<ValuedSlider value={selectedConfig.modelParameters.storedLayers} min={0}
|
||||
max={selectedConfig.modelParameters.maxStoredLayers} step={1} input
|
||||
onChange={(e, data) => {
|
||||
setSelectedConfigModelParams({
|
||||
precision: data.optionText as Precision
|
||||
storedLayers: data.value
|
||||
});
|
||||
}
|
||||
}}>
|
||||
<Option>fp16</Option>
|
||||
<Option>int8</Option>
|
||||
<Option>fp32</Option>
|
||||
</Dropdown>
|
||||
} />
|
||||
<div />
|
||||
<Labeled label={t('Stored Layers')}
|
||||
desc={t('Number of the neural network layers loaded into VRAM, the more you load, the faster the speed, but it consumes more VRAM.')}
|
||||
content={
|
||||
<ValuedSlider value={selectedConfig.modelParameters.storedLayers} min={0}
|
||||
max={selectedConfig.modelParameters.maxStoredLayers} step={1} input
|
||||
onChange={(e, data) => {
|
||||
setSelectedConfigModelParams({
|
||||
storedLayers: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled label={t('Enable High Precision For Last Layer')}
|
||||
desc={t('Whether to use CPU to calculate the last output layer of the neural network with FP32 precision to obtain better quality.')}
|
||||
content={
|
||||
<Switch checked={selectedConfig.modelParameters.enableHighPrecisionForLastLayer}
|
||||
onChange={(e, data) => {
|
||||
setSelectedConfigModelParams({
|
||||
enableHighPrecisionForLastLayer: data.checked
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled label={t('Use Custom CUDA kernel to Accelerate')}
|
||||
desc={t('Enabling this option can greatly improve inference speed, but there may be compatibility issues. If it fails to start, please turn off this option.')}
|
||||
content={
|
||||
<Switch checked={selectedConfig.modelParameters.useCustomCuda}
|
||||
onChange={(e, data) => {
|
||||
setSelectedConfigModelParams({
|
||||
useCustomCuda: data.checked
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
}} />
|
||||
} />
|
||||
}
|
||||
{
|
||||
selectedConfig.modelParameters.device == 'CUDA' && <div />
|
||||
}
|
||||
{
|
||||
displayStrategyImg &&
|
||||
<img style={{ width: '80vh', height: 'auto', zIndex: 100 }}
|
||||
className="fixed left-0 top-0 rounded-xl select-none"
|
||||
src={commonStore.settings.language === 'zh' ? strategyZhImg : strategyImg} />
|
||||
}
|
||||
{
|
||||
selectedConfig.modelParameters.device == 'Custom' &&
|
||||
<Labeled label="Strategy"
|
||||
onMouseEnter={() => setDisplayStrategyImg(true)}
|
||||
onMouseLeave={() => setDisplayStrategyImg(false)}
|
||||
content={
|
||||
<Input className="grow"
|
||||
placeholder={commonStore.platform != 'darwin' ? 'cuda:0 fp16 *20 -> cuda:1 fp16' : 'mps fp32'}
|
||||
value={selectedConfig.modelParameters.customStrategy}
|
||||
onChange={(e, data) => {
|
||||
setSelectedConfigModelParams({
|
||||
customStrategy: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
}
|
||||
{selectedConfig.modelParameters.device == 'Custom' && <div />}
|
||||
{
|
||||
selectedConfig.modelParameters.device != 'CPU' && selectedConfig.modelParameters.device != 'MPS' &&
|
||||
<Labeled label={t('Use Custom CUDA kernel to Accelerate')}
|
||||
desc={t('Enabling this option can greatly improve inference speed and save some VRAM, but there may be compatibility issues. If it fails to start, please turn off this option.')}
|
||||
content={
|
||||
<Switch checked={selectedConfig.modelParameters.useCustomCuda}
|
||||
onChange={(e, data) => {
|
||||
setSelectedConfigModelParams({
|
||||
useCustomCuda: data.checked
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import React, { FC, useEffect } from 'react';
|
||||
import React, { FC } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Page } from '../components/Page';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import commonStore from '../stores/commonStore';
|
||||
import { Divider, Field, ProgressBar } from '@fluentui/react-components';
|
||||
import { bytesToGb, bytesToKb, bytesToMb, refreshLocalModels } from '../utils';
|
||||
import { bytesToGb, bytesToKb, bytesToMb } from '../utils';
|
||||
import { ToolTipButton } from '../components/ToolTipButton';
|
||||
import { Folder20Regular, Pause20Regular, Play20Regular } from '@fluentui/react-icons';
|
||||
import { ContinueDownload, OpenFileFolder, PauseDownload } from '../../wailsjs/go/backend_golang/App';
|
||||
import { AddToDownloadList, OpenFileFolder, PauseDownload } from '../../wailsjs/go/backend_golang/App';
|
||||
|
||||
export type DownloadStatus = {
|
||||
name: string;
|
||||
@@ -23,17 +23,28 @@ export type DownloadStatus = {
|
||||
|
||||
export const Downloads: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
const finishedModelsLen = commonStore.downloadList.filter((status) => status.done && status.name.endsWith('.pth')).length;
|
||||
useEffect(() => {
|
||||
if (finishedModelsLen > 0)
|
||||
refreshLocalModels({ models: commonStore.modelSourceList }, false);
|
||||
console.log('finishedModelsLen:', finishedModelsLen);
|
||||
}, [finishedModelsLen]);
|
||||
|
||||
let displayList = commonStore.downloadList.slice();
|
||||
const downloadListNames = displayList.map(s => s.name);
|
||||
commonStore.lastUnfinishedModelDownloads.forEach((status) => {
|
||||
const unfinishedIndex = downloadListNames.indexOf(status.name);
|
||||
if (unfinishedIndex === -1) {
|
||||
displayList.push(status);
|
||||
} else {
|
||||
const unfinishedStatus = displayList[unfinishedIndex];
|
||||
if (unfinishedStatus.transferred < status.transferred) {
|
||||
status.downloading = unfinishedStatus.downloading;
|
||||
delete displayList[unfinishedIndex];
|
||||
displayList.push(status);
|
||||
}
|
||||
}
|
||||
});
|
||||
displayList = displayList.reverse();
|
||||
|
||||
return (
|
||||
<Page title={t('Downloads')} content={
|
||||
<div className="flex flex-col gap-2 overflow-y-auto overflow-x-hidden p-1">
|
||||
{commonStore.downloadList.slice().reverse().map((status, index) => {
|
||||
{displayList.map((status, index) => {
|
||||
const downloadProgress = `${status.progress.toFixed(2)}%`;
|
||||
const downloadSpeed = `${status.downloading ? bytesToMb(status.speed) : '0'}MB/s`;
|
||||
let downloadDetails: string;
|
||||
@@ -53,16 +64,16 @@ export const Downloads: FC = observer(() => {
|
||||
<div className="flex items-center gap-2">
|
||||
<ProgressBar className="grow" value={status.progress} max={100} />
|
||||
{!status.done &&
|
||||
<ToolTipButton desc={status.downloading ? t('Pause') : t('Continue')}
|
||||
<ToolTipButton desc={status.downloading ? t('Pause') : t('Resume')}
|
||||
icon={status.downloading ? <Pause20Regular /> : <Play20Regular />}
|
||||
onClick={() => {
|
||||
if (status.downloading)
|
||||
PauseDownload(status.url);
|
||||
else
|
||||
ContinueDownload(status.url);
|
||||
AddToDownloadList(status.path, status.url);
|
||||
}} />}
|
||||
<ToolTipButton desc={t('Open Folder')} icon={<Folder20Regular />} onClick={() => {
|
||||
OpenFileFolder(status.path);
|
||||
OpenFileFolder(status.path, false);
|
||||
}} />
|
||||
</div>
|
||||
</Field>
|
||||
|
||||
@@ -3,9 +3,9 @@ import React, { FC, ReactElement } from 'react';
|
||||
import banner from '../assets/images/banner.jpg';
|
||||
import {
|
||||
Chat20Regular,
|
||||
ClipboardEdit20Regular,
|
||||
DataUsageSettings20Regular,
|
||||
DocumentSettings20Regular,
|
||||
Storage20Regular
|
||||
DocumentSettings20Regular
|
||||
} from '@fluentui/react-icons';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
@@ -16,6 +16,8 @@ import { useTranslation } from 'react-i18next';
|
||||
import { ConfigSelector } from '../components/ConfigSelector';
|
||||
import MarkdownRender from '../components/MarkdownRender';
|
||||
import commonStore from '../stores/commonStore';
|
||||
import { Completion } from './Completion';
|
||||
import { ResetConfigsButton } from '../components/ResetConfigsButton';
|
||||
|
||||
export type IntroductionContent = { [lang: string]: string }
|
||||
|
||||
@@ -33,6 +35,12 @@ const navCards: NavCard[] = [
|
||||
path: '/chat',
|
||||
icon: <Chat20Regular />
|
||||
},
|
||||
{
|
||||
label: 'Completion',
|
||||
desc: 'Writer, Translator, Role-playing',
|
||||
path: '/completion',
|
||||
icon: <ClipboardEdit20Regular />
|
||||
},
|
||||
{
|
||||
label: 'Configs',
|
||||
desc: 'Manage your configs',
|
||||
@@ -44,12 +52,6 @@ const navCards: NavCard[] = [
|
||||
desc: 'Manage models',
|
||||
path: '/models',
|
||||
icon: <DataUsageSettings20Regular />
|
||||
},
|
||||
{
|
||||
label: 'Train',
|
||||
desc: '',
|
||||
path: '/train',
|
||||
icon: <Storage20Regular />
|
||||
}
|
||||
];
|
||||
|
||||
@@ -64,7 +66,8 @@ export const Home: FC = observer(() => {
|
||||
|
||||
return (
|
||||
<div className="flex flex-col justify-between h-full">
|
||||
<img className="rounded-xl select-none hidden sm:block" src={banner} />
|
||||
<img className="rounded-xl select-none hidden sm:block"
|
||||
style={{ maxHeight: '40%', margin: '0 auto' }} src={banner} />
|
||||
<div className="flex flex-col gap-2">
|
||||
<Text size={600} weight="medium">{t('Introduction')}</Text>
|
||||
<div className="h-40 overflow-y-auto overflow-x-hidden p-1">
|
||||
@@ -84,6 +87,7 @@ export const Home: FC = observer(() => {
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex flex-row-reverse sm:fixed bottom-2 right-2">
|
||||
<div className="flex gap-3">
|
||||
<ResetConfigsButton />
|
||||
<ConfigSelector />
|
||||
<RunButton />
|
||||
</div>
|
||||
|
||||
@@ -18,7 +18,6 @@ import { observer } from 'mobx-react-lite';
|
||||
import commonStore from '../stores/commonStore';
|
||||
import { BrowserOpenURL } from '../../wailsjs/runtime';
|
||||
import { AddToDownloadList, OpenFileFolder } from '../../wailsjs/go/backend_golang/App';
|
||||
import manifest from '../../../manifest.json';
|
||||
import { Page } from '../components/Page';
|
||||
import { bytesToGb, refreshModels, saveConfigs, toastWithButton } from '../utils';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
@@ -32,8 +31,11 @@ export type ModelSourceItem = {
|
||||
SHA256?: string;
|
||||
url?: string;
|
||||
downloadUrl?: string;
|
||||
isComplete?: boolean;
|
||||
isLocal?: boolean;
|
||||
localSize?: number;
|
||||
lastUpdatedMs?: number;
|
||||
hide?: boolean;
|
||||
};
|
||||
|
||||
const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
@@ -125,7 +127,7 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
createTableColumn<ModelSourceItem>({
|
||||
columnId: 'actions',
|
||||
compare: (a, b) => {
|
||||
return a.isLocal ? -1 : 1;
|
||||
return a.isComplete ? -1 : 1;
|
||||
},
|
||||
renderHeaderCell: () => {
|
||||
const { t } = useTranslation();
|
||||
@@ -140,18 +142,18 @@ const columns: TableColumnDefinition<ModelSourceItem>[] = [
|
||||
<TableCellLayout>
|
||||
<div className="flex gap-1">
|
||||
{
|
||||
item.isLocal &&
|
||||
item.isComplete &&
|
||||
<ToolTipButton desc={t('Open Folder')} icon={<Folder20Regular />} onClick={() => {
|
||||
OpenFileFolder(`./${manifest.localModelDir}/${item.name}`);
|
||||
OpenFileFolder(`${commonStore.settings.customModelsPath}/${item.name}`, true);
|
||||
}} />
|
||||
}
|
||||
{item.downloadUrl && !item.isLocal &&
|
||||
{item.downloadUrl && !item.isComplete &&
|
||||
<ToolTipButton desc={t('Download')} icon={<ArrowDownload20Regular />} onClick={() => {
|
||||
toastWithButton(`${t('Downloading')} ${item.name}`, t('Check'), () => {
|
||||
navigate({ pathname: '/downloads' });
|
||||
},
|
||||
{ autoClose: 3000 });
|
||||
AddToDownloadList(`./${manifest.localModelDir}/${item.name}`, item.downloadUrl!);
|
||||
AddToDownloadList(`${commonStore.settings.customModelsPath}/${item.name}`, item.downloadUrl!);
|
||||
}} />}
|
||||
{item.url && <ToolTipButton desc={t('Open Url')} icon={<Open20Regular />} onClick={() => {
|
||||
BrowserOpenURL(item.url!);
|
||||
@@ -203,6 +205,7 @@ export const Models: FC = observer(() => {
|
||||
<div className="overflow-y-auto overflow-x-hidden">
|
||||
<DataGridBody<ModelSourceItem>>
|
||||
{({ item, rowId }) => (
|
||||
(!item.hide || item.isComplete) &&
|
||||
<DataGridRow<ModelSourceItem> key={rowId}>
|
||||
{({ renderCell }) => (
|
||||
<DataGridCell>{renderCell(item)}</DataGridCell>
|
||||
|
||||
154
frontend/src/pages/PresetsManager/MessagesEditor.tsx
Normal file
@@ -0,0 +1,154 @@
|
||||
import React, { FC, useState } from 'react';
|
||||
import { DragDropContext, Draggable, Droppable, DropResult } from 'react-beautiful-dnd';
|
||||
import commonStore from '../../stores/commonStore';
|
||||
import { Preset } from './PresetsButton';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
import { Button, Card, Dropdown, Option, Textarea } from '@fluentui/react-components';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { ToolTipButton } from '../../components/ToolTipButton';
|
||||
import { Delete20Regular, ReOrderDotsVertical20Regular } from '@fluentui/react-icons';
|
||||
import { ConversationMessage, Role } from '../Chat';
|
||||
|
||||
type Item = {
|
||||
id: string;
|
||||
role: Role;
|
||||
content: string;
|
||||
}
|
||||
|
||||
const getItems = (messages: ConversationMessage[]) =>
|
||||
messages.map((message, index) => ({
|
||||
id: uuid(),
|
||||
role: message.role,
|
||||
content: message.content
|
||||
})) as Item[];
|
||||
|
||||
const reorder = (list: Item[], startIndex: number, endIndex: number) => {
|
||||
const result = Array.from(list);
|
||||
const [removed] = result.splice(startIndex, 1);
|
||||
result.splice(endIndex, 0, removed);
|
||||
|
||||
return result;
|
||||
};
|
||||
|
||||
export const MessagesEditor: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const editingPreset = commonStore.editingPreset!;
|
||||
const setEditingPreset = (newParams: Partial<Preset>) => {
|
||||
commonStore.setEditingPreset({
|
||||
...editingPreset,
|
||||
...newParams
|
||||
});
|
||||
};
|
||||
|
||||
const [items, setItems] = useState(getItems(editingPreset.messages));
|
||||
|
||||
const updateItems = (items: Item[]) => {
|
||||
setEditingPreset({
|
||||
messages: items.map(item => ({
|
||||
role: item.role,
|
||||
content: item.content
|
||||
}))
|
||||
});
|
||||
setItems(items);
|
||||
};
|
||||
|
||||
const onDragEnd = (result: DropResult) => {
|
||||
if (!result.destination) {
|
||||
return;
|
||||
}
|
||||
|
||||
const newItems = reorder(
|
||||
items,
|
||||
result.source.index,
|
||||
result.destination.index
|
||||
);
|
||||
|
||||
updateItems(newItems);
|
||||
};
|
||||
|
||||
const createNewItem = () => {
|
||||
const newItems: Item[] = [...items, {
|
||||
id: uuid(),
|
||||
role: 'assistant',
|
||||
content: ''
|
||||
}];
|
||||
updateItems(newItems);
|
||||
};
|
||||
|
||||
const deleteItem = (id: string) => {
|
||||
const newItems: Item[] = items.filter(item => item.id !== id);
|
||||
updateItems(newItems);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-1 gap-2 overflow-hidden">
|
||||
<Button style={{ width: '100%' }} onClick={createNewItem}>{t('New')}</Button>
|
||||
<div className="overflow-x-hidden overflow-y-auto p-2">
|
||||
<DragDropContext onDragEnd={onDragEnd}>
|
||||
<Droppable droppableId="droppable">
|
||||
{(provided, snapshot) => (
|
||||
<div
|
||||
{...provided.droppableProps}
|
||||
ref={provided.innerRef}
|
||||
>
|
||||
{items.map((item, index) => (
|
||||
<Draggable key={item.id} draggableId={item.id} index={index}>
|
||||
{(provided, snapshot) => (
|
||||
<div
|
||||
ref={provided.innerRef}
|
||||
{...provided.draggableProps}
|
||||
{...provided.dragHandleProps}
|
||||
style={provided.draggableProps.style}
|
||||
className="select-none mb-2"
|
||||
>
|
||||
<div className="flex">
|
||||
<Card appearance="outline"
|
||||
style={{ borderTopRightRadius: 0, borderBottomRightRadius: 0 }}>
|
||||
<ReOrderDotsVertical20Regular />
|
||||
</Card>
|
||||
<Dropdown style={{ minWidth: 0, borderRadius: 0 }} listbox={{ style: { minWidth: 0 } }}
|
||||
value={t(item.role)!}
|
||||
selectedOptions={[item.role]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue) {
|
||||
items[index] = {
|
||||
...item,
|
||||
role: data.optionValue as Role
|
||||
};
|
||||
updateItems([...items]);
|
||||
}
|
||||
}}>
|
||||
<Option value="user">{t('user')!}</Option>
|
||||
<Option value="assistant">{t('assistant')!}</Option>
|
||||
{/* TODO <Option value="system">{t('system')!}</Option>*/}
|
||||
</Dropdown>
|
||||
<Textarea resize="vertical" className="grow" value={item.content}
|
||||
style={{ minWidth: 0, borderRadius: 0 }}
|
||||
onChange={(e, data) => {
|
||||
items[index] = {
|
||||
...item,
|
||||
content: data.value
|
||||
};
|
||||
updateItems([...items]);
|
||||
}}></Textarea>
|
||||
<ToolTipButton
|
||||
style={{ borderTopLeftRadius: 0, borderBottomLeftRadius: 0 }} desc={t('Delete')}
|
||||
icon={<Delete20Regular />} onClick={() => {
|
||||
deleteItem(item.id);
|
||||
}} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</Draggable>
|
||||
))}
|
||||
{provided.placeholder}
|
||||
</div>
|
||||
)}
|
||||
</Droppable>
|
||||
</DragDropContext>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
431
frontend/src/pages/PresetsManager/PresetsButton.tsx
Normal file
@@ -0,0 +1,431 @@
|
||||
// TODO refactor
|
||||
|
||||
import React, { FC, PropsWithChildren, ReactElement, useState } from 'react';
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
DialogBody,
|
||||
DialogContent,
|
||||
DialogSurface,
|
||||
DialogTrigger,
|
||||
Input,
|
||||
Switch,
|
||||
Tab,
|
||||
TabList,
|
||||
Text
|
||||
} from '@fluentui/react-components';
|
||||
import {
|
||||
Accessibility28Regular,
|
||||
Chat20Regular,
|
||||
ClipboardEdit20Regular,
|
||||
Delete20Regular,
|
||||
Dismiss20Regular,
|
||||
Edit20Regular,
|
||||
Globe20Regular
|
||||
} from '@fluentui/react-icons';
|
||||
import { ToolTipButton } from '../../components/ToolTipButton';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { botName, Conversation, ConversationMessage, MessageType, userName } from '../Chat';
|
||||
import { SelectTabEventHandler } from '@fluentui/react-tabs';
|
||||
import { Labeled } from '../../components/Labeled';
|
||||
import commonStore from '../../stores/commonStore';
|
||||
import logo from '../../assets/images/logo.png';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { MessagesEditor } from './MessagesEditor';
|
||||
import { ClipboardGetText, ClipboardSetText } from '../../../wailsjs/runtime';
|
||||
import { toast } from 'react-toastify';
|
||||
import { CustomToastContainer } from '../../components/CustomToastContainer';
|
||||
import { v4 as uuid } from 'uuid';
|
||||
|
||||
export type PresetType = 'chat' | 'completion' | 'chatInCompletion'
|
||||
|
||||
export type Preset = {
|
||||
name: string,
|
||||
tag: string,
|
||||
// if name and sourceUrl are same, it will be overridden when importing
|
||||
sourceUrl: string,
|
||||
desc: string,
|
||||
avatarImg: string,
|
||||
type: PresetType,
|
||||
// chat
|
||||
welcomeMessage: string,
|
||||
messages: ConversationMessage[],
|
||||
displayPresetMessages: boolean,
|
||||
// completion
|
||||
prompt: string,
|
||||
stop: string,
|
||||
injectStart: string,
|
||||
injectEnd: string,
|
||||
}
|
||||
|
||||
export const defaultPreset: Preset = {
|
||||
name: 'RWKV',
|
||||
tag: 'default',
|
||||
sourceUrl: '',
|
||||
desc: '',
|
||||
avatarImg: logo,
|
||||
type: 'chat',
|
||||
welcomeMessage: '',
|
||||
displayPresetMessages: true,
|
||||
messages: [],
|
||||
prompt: '',
|
||||
stop: '',
|
||||
injectStart: '',
|
||||
injectEnd: ''
|
||||
};
|
||||
|
||||
const setActivePreset = (preset: Preset) => {
|
||||
commonStore.setActivePreset(preset);
|
||||
//TODO if (preset.displayPresetMessages) {
|
||||
const conversation: Conversation = {};
|
||||
const conversationOrder: string[] = [];
|
||||
for (const message of preset.messages) {
|
||||
const newUuid = uuid();
|
||||
conversationOrder.push(newUuid);
|
||||
conversation[newUuid] = {
|
||||
sender: message.role === 'user' ? userName : botName,
|
||||
type: MessageType.Normal,
|
||||
color: message.role === 'user' ? 'brand' : 'colorful',
|
||||
time: new Date().toISOString(),
|
||||
content: message.content,
|
||||
side: message.role === 'user' ? 'right' : 'left',
|
||||
done: true
|
||||
};
|
||||
}
|
||||
commonStore.setConversation(conversation);
|
||||
commonStore.setConversationOrder(conversationOrder);
|
||||
//}
|
||||
};
|
||||
|
||||
export const PresetCardFrame: FC<PropsWithChildren & { onClick?: () => void }> = (props) => {
|
||||
return <Button
|
||||
className="flex flex-col gap-1 w-32 h-56 break-all"
|
||||
style={{ minWidth: 0, borderRadius: '0.75rem', justifyContent: 'unset' }}
|
||||
onClick={props.onClick}
|
||||
>
|
||||
{props.children}
|
||||
</Button>;
|
||||
};
|
||||
|
||||
export const PresetCard: FC<{
|
||||
avatarImg: string,
|
||||
name: string,
|
||||
desc: string,
|
||||
tag: string,
|
||||
editable: boolean,
|
||||
presetIndex: number,
|
||||
onClick?: () => void
|
||||
}> = observer(({
|
||||
avatarImg, name, desc, tag, editable, presetIndex, onClick
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return <PresetCardFrame onClick={onClick}>
|
||||
<img src={avatarImg} className="rounded-xl select-none ml-auto mr-auto h-28" />
|
||||
<Text size={400}>{name}</Text>
|
||||
<Text size={200} style={{
|
||||
overflow: 'hidden', textOverflow: 'ellipsis',
|
||||
display: '-webkit-box', WebkitLineClamp: 3, WebkitBoxOrient: 'vertical'
|
||||
}}>{desc}</Text>
|
||||
<div className="grow" />
|
||||
<div className="flex justify-between w-full items-end">
|
||||
<div className="text-xs font-thin text-gray-500">{t(tag)}</div>
|
||||
{editable ?
|
||||
<ChatPresetEditor presetIndex={presetIndex} triggerButton={
|
||||
<ToolTipButton size="small" appearance="transparent" desc={t('Edit')} icon={<Edit20Regular />}
|
||||
onClick={() => {
|
||||
commonStore.setEditingPreset({ ...commonStore.presets[presetIndex] });
|
||||
}} />
|
||||
} />
|
||||
: <div />
|
||||
}
|
||||
</div>
|
||||
</PresetCardFrame>;
|
||||
});
|
||||
|
||||
export const ChatPresetEditor: FC<{
|
||||
triggerButton: ReactElement,
|
||||
presetIndex: number
|
||||
}> = observer(({ triggerButton, presetIndex }) => {
|
||||
const { t } = useTranslation();
|
||||
const [editingMessages, setEditingMessages] = useState(false);
|
||||
|
||||
if (!commonStore.editingPreset)
|
||||
commonStore.setEditingPreset({ ...defaultPreset });
|
||||
const editingPreset = commonStore.editingPreset!;
|
||||
|
||||
const setEditingPreset = (newParams: Partial<Preset>) => {
|
||||
commonStore.setEditingPreset({
|
||||
...editingPreset,
|
||||
...newParams
|
||||
});
|
||||
};
|
||||
|
||||
const importPreset = () => {
|
||||
ClipboardGetText().then((text) => {
|
||||
try {
|
||||
const preset = JSON.parse(text);
|
||||
setEditingPreset(preset);
|
||||
toast(t('Imported successfully'), {
|
||||
type: 'success',
|
||||
autoClose: 1000
|
||||
});
|
||||
} catch (e) {
|
||||
toast(t('Failed to import. Please copy a preset to the clipboard.'), {
|
||||
type: 'error',
|
||||
autoClose: 2500
|
||||
});
|
||||
}
|
||||
}).catch(() => {
|
||||
toast(t('Clipboard is empty.'), {
|
||||
type: 'info',
|
||||
autoClose: 1000
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const copyPreset = () => {
|
||||
ClipboardSetText(JSON.stringify(editingPreset)).then((success) => {
|
||||
if (success)
|
||||
toast(t('Successfully copied to clipboard.'), {
|
||||
type: 'success',
|
||||
autoClose: 1000
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const savePreset = () => {
|
||||
if (presetIndex === -1) {
|
||||
commonStore.setPresets([...commonStore.presets, { ...editingPreset }]);
|
||||
setEditingPreset(defaultPreset);
|
||||
} else {
|
||||
commonStore.presets[presetIndex] = editingPreset;
|
||||
commonStore.setPresets(commonStore.presets);
|
||||
}
|
||||
};
|
||||
|
||||
const activatePreset = () => {
|
||||
savePreset();
|
||||
setActivePreset(editingPreset);
|
||||
};
|
||||
|
||||
const deletePreset = () => {
|
||||
commonStore.presets.splice(presetIndex, 1);
|
||||
commonStore.setPresets(commonStore.presets);
|
||||
};
|
||||
|
||||
return <Dialog>
|
||||
<DialogTrigger disableButtonEnhancement>
|
||||
{triggerButton}
|
||||
</DialogTrigger>
|
||||
<DialogSurface style={{
|
||||
paddingTop: 0,
|
||||
maxWidth: '80vw',
|
||||
maxHeight: '80vh',
|
||||
width: '500px',
|
||||
height: '100%'
|
||||
}}>
|
||||
<DialogBody style={{ height: '100%', overflow: 'hidden' }}>
|
||||
<DialogContent className="flex flex-col gap-1 overflow-hidden">
|
||||
<CustomToastContainer />
|
||||
<div className="flex justify-between">{
|
||||
presetIndex === -1
|
||||
? <div />
|
||||
: <DialogTrigger disableButtonEnhancement>
|
||||
<Button appearance="subtle" icon={<Delete20Regular />} onClick={deletePreset} />
|
||||
</DialogTrigger>
|
||||
}
|
||||
<DialogTrigger disableButtonEnhancement>
|
||||
<Button appearance="subtle" icon={<Dismiss20Regular />} />
|
||||
</DialogTrigger>
|
||||
</div>
|
||||
<img src={editingPreset.avatarImg} className="rounded-xl select-none ml-auto mr-auto h-28" />
|
||||
<Labeled flex breakline label={t('Name')}
|
||||
content={
|
||||
<div className="flex gap-2">
|
||||
<Input className="grow" value={editingPreset.name} onChange={(e, data) => {
|
||||
setEditingPreset({
|
||||
name: data.value
|
||||
});
|
||||
}} />
|
||||
<Button onClick={() => {
|
||||
setEditingMessages(!editingMessages);
|
||||
}}>{!editingMessages ? t('Edit Messages') : t('Go Back')}</Button>
|
||||
</div>
|
||||
} />
|
||||
{
|
||||
editingMessages ?
|
||||
<MessagesEditor /> :
|
||||
<div className="flex flex-col gap-1 p-2 overflow-x-hidden overflow-y-auto">
|
||||
<Labeled flex breakline label={t('Description')}
|
||||
content={
|
||||
<Input value={editingPreset.desc} onChange={(e, data) => {
|
||||
setEditingPreset({
|
||||
desc: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled flex breakline label={t('Avatar Url')}
|
||||
content={
|
||||
<Input value={editingPreset.avatarImg} onChange={(e, data) => {
|
||||
setEditingPreset({
|
||||
avatarImg: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled flex breakline label={t('Welcome Message')}
|
||||
content={
|
||||
<Input disabled value={editingPreset.welcomeMessage} onChange={(e, data) => {
|
||||
setEditingPreset({
|
||||
welcomeMessage: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled flex spaceBetween label={t('Display Preset Messages')}
|
||||
content={
|
||||
<Switch disabled checked={editingPreset.displayPresetMessages}
|
||||
onChange={(e, data) => {
|
||||
setEditingPreset({
|
||||
displayPresetMessages: data.checked
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled flex breakline label={t('Tag')}
|
||||
content={
|
||||
<Input value={editingPreset.tag} onChange={(e, data) => {
|
||||
setEditingPreset({
|
||||
tag: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
</div>
|
||||
}
|
||||
<div className="grow" />
|
||||
<div className="flex justify-between">
|
||||
<Button onClick={importPreset}>{t('Import')}</Button>
|
||||
<Button onClick={copyPreset}>{t('Copy')}</Button>
|
||||
</div>
|
||||
<div className="flex justify-between">
|
||||
<DialogTrigger disableButtonEnhancement>
|
||||
<Button appearance="primary" onClick={savePreset}>{t('Save')}</Button>
|
||||
</DialogTrigger>
|
||||
<DialogTrigger disableButtonEnhancement>
|
||||
<Button appearance="primary" onClick={activatePreset}>{t('Activate')}</Button>
|
||||
</DialogTrigger>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</DialogBody>
|
||||
</DialogSurface>
|
||||
</Dialog>;
|
||||
});
|
||||
|
||||
export const ChatPresets: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return <div className="flex flex-wrap gap-2">
|
||||
<ChatPresetEditor presetIndex={-1} triggerButton={
|
||||
<PresetCardFrame>
|
||||
<div className="h-full flex items-center">
|
||||
{t('New Preset')}
|
||||
</div>
|
||||
</PresetCardFrame>}
|
||||
/>
|
||||
{/*TODO <PresetCardFrame>*/}
|
||||
{/* <div className="h-full flex items-center">*/}
|
||||
{/* {t('Import')}*/}
|
||||
{/* </div>*/}
|
||||
{/*</PresetCardFrame>*/}
|
||||
<PresetCard
|
||||
presetIndex={-1}
|
||||
editable={false}
|
||||
onClick={() => {
|
||||
setActivePreset(defaultPreset);
|
||||
}} avatarImg={defaultPreset.avatarImg} name={defaultPreset.name} desc={defaultPreset.desc} tag={defaultPreset.tag}
|
||||
/>
|
||||
{commonStore.presets.map((preset, index) => {
|
||||
return <PresetCard
|
||||
presetIndex={index}
|
||||
editable={true}
|
||||
onClick={() => {
|
||||
setActivePreset(preset);
|
||||
}}
|
||||
key={index} avatarImg={preset.avatarImg} name={preset.name} desc={preset.desc} tag={preset.tag}
|
||||
/>;
|
||||
})}
|
||||
</div>;
|
||||
});
|
||||
|
||||
type PresetsNavigationItem = {
|
||||
icon: ReactElement;
|
||||
element: ReactElement;
|
||||
};
|
||||
|
||||
const pages: { [label: string]: PresetsNavigationItem } = {
|
||||
Chat: {
|
||||
icon: <Chat20Regular />,
|
||||
element: <ChatPresets />
|
||||
},
|
||||
Completion: {
|
||||
icon: <ClipboardEdit20Regular />,
|
||||
element: <div>In Development</div>
|
||||
},
|
||||
Online: {
|
||||
icon: <Globe20Regular />,
|
||||
element: <div>In Development</div>
|
||||
}
|
||||
};
|
||||
|
||||
export const PresetsManager: FC<{ initTab: string }> = ({ initTab }) => {
|
||||
const { t } = useTranslation();
|
||||
const [tab, setTab] = useState(initTab);
|
||||
|
||||
const selectTab: SelectTabEventHandler = (e, data) =>
|
||||
typeof data.value === 'string' ? setTab(data.value) : null;
|
||||
|
||||
return <div className="flex flex-col gap-2 w-full h-full">
|
||||
<div className="flex justify-between">
|
||||
<TabList
|
||||
size="small"
|
||||
appearance="subtle"
|
||||
selectedValue={tab}
|
||||
onTabSelect={selectTab}
|
||||
>
|
||||
{Object.entries(pages).map(([label, { icon }]) => (
|
||||
<Tab icon={icon} key={label} value={label}>
|
||||
{t(label)}
|
||||
</Tab>
|
||||
))}
|
||||
</TabList>
|
||||
<DialogTrigger disableButtonEnhancement>
|
||||
<Button appearance="subtle" icon={<Dismiss20Regular />} />
|
||||
</DialogTrigger>
|
||||
</div>
|
||||
<div className="grow overflow-x-hidden overflow-y-auto">
|
||||
{pages[tab].element}
|
||||
</div>
|
||||
</div>;
|
||||
};
|
||||
|
||||
export const PresetsButton: FC<{
|
||||
tab: string,
|
||||
size?: 'small' | 'medium' | 'large',
|
||||
shape?: 'rounded' | 'circular' | 'square';
|
||||
appearance?: 'secondary' | 'primary' | 'outline' | 'subtle' | 'transparent';
|
||||
}> = ({ tab, size, shape, appearance }) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return <Dialog>
|
||||
<DialogTrigger disableButtonEnhancement>
|
||||
<ToolTipButton desc={t('Presets')} size={size} shape={shape} appearance={appearance}
|
||||
icon={<Accessibility28Regular />} />
|
||||
</DialogTrigger>
|
||||
<DialogSurface style={{ paddingTop: 0, maxWidth: '90vw', width: 'fit-content' }}>
|
||||
<DialogBody>
|
||||
<DialogContent>
|
||||
<CustomToastContainer />
|
||||
<PresetsManager initTab={tab} />
|
||||
</DialogContent>
|
||||
</DialogBody>
|
||||
</DialogSurface>
|
||||
</Dialog>;
|
||||
};
|
||||
@@ -1,11 +1,21 @@
|
||||
import React, { FC } from 'react';
|
||||
import React, { FC, useEffect, useRef } from 'react';
|
||||
import { Page } from '../components/Page';
|
||||
import { Dropdown, Input, Option, Switch } from '@fluentui/react-components';
|
||||
import {
|
||||
Accordion,
|
||||
AccordionHeader,
|
||||
AccordionItem,
|
||||
AccordionPanel,
|
||||
Dropdown,
|
||||
Input,
|
||||
Option,
|
||||
Switch
|
||||
} from '@fluentui/react-components';
|
||||
import { Labeled } from '../components/Labeled';
|
||||
import commonStore from '../stores/commonStore';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { checkUpdate } from '../utils';
|
||||
import { checkUpdate, toastWithButton } from '../utils';
|
||||
import { RestartApp } from '../../wailsjs/go/backend_golang/App';
|
||||
|
||||
export const Languages = {
|
||||
dev: 'English', // i18n default
|
||||
@@ -15,20 +25,33 @@ export const Languages = {
|
||||
export type Language = keyof typeof Languages;
|
||||
|
||||
export type SettingsType = {
|
||||
language: Language,
|
||||
language: Language
|
||||
darkMode: boolean
|
||||
autoUpdatesCheck: boolean
|
||||
giteeUpdatesSource: boolean
|
||||
cnMirror: boolean
|
||||
host: string
|
||||
dpiScaling: number
|
||||
customModelsPath: string
|
||||
customPythonPath: string
|
||||
apiUrl: string
|
||||
apiKey: string
|
||||
apiChatModelName: string
|
||||
apiCompletionModelName: string
|
||||
}
|
||||
|
||||
export const Settings: FC = observer(() => {
|
||||
const { t, i18n } = useTranslation();
|
||||
const advancedHeaderRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
if (advancedHeaderRef.current)
|
||||
(advancedHeaderRef.current.firstElementChild as HTMLElement).style.padding = '0';
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<Page title={t('Settings')} content={
|
||||
<div className="flex flex-col gap-2 overflow-hidden">
|
||||
<div className="flex flex-col gap-2 overflow-y-auto overflow-x-hidden p-1">
|
||||
<Labeled label={t('Language')} flex spaceBetween content={
|
||||
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
|
||||
value={Languages[commonStore.settings.language]}
|
||||
@@ -39,7 +62,6 @@ export const Settings: FC = observer(() => {
|
||||
commonStore.setSettings({
|
||||
language: lang
|
||||
});
|
||||
i18n.changeLanguage(lang);
|
||||
}
|
||||
}}>
|
||||
{
|
||||
@@ -48,6 +70,31 @@ export const Settings: FC = observer(() => {
|
||||
}
|
||||
</Dropdown>
|
||||
} />
|
||||
{
|
||||
commonStore.platform === 'windows' &&
|
||||
<Labeled label={t('DPI Scaling')} flex spaceBetween content={
|
||||
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
|
||||
value={commonStore.settings.dpiScaling + '%'}
|
||||
selectedOptions={[commonStore.settings.dpiScaling.toString()]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue) {
|
||||
commonStore.setSettings({
|
||||
dpiScaling: Number(data.optionValue)
|
||||
});
|
||||
toastWithButton(t('Restart the app to apply DPI Scaling.'), t('Restart'), () => {
|
||||
RestartApp();
|
||||
}, {
|
||||
autoClose: 5000
|
||||
});
|
||||
}
|
||||
}}>
|
||||
{
|
||||
Array.from({ length: 7 }, (_, i) => (i + 2) * 25).map((v, i) =>
|
||||
<Option key={i} value={v.toString()}>{v + '%'}</Option>)
|
||||
}
|
||||
</Dropdown>
|
||||
} />
|
||||
}
|
||||
<Labeled label={t('Dark Mode')} flex spaceBetween content={
|
||||
<Switch checked={commonStore.settings.darkMode}
|
||||
onChange={(e, data) => {
|
||||
@@ -78,7 +125,7 @@ export const Settings: FC = observer(() => {
|
||||
} />
|
||||
}
|
||||
{
|
||||
commonStore.settings.language === 'zh' &&
|
||||
commonStore.settings.language === 'zh' && commonStore.platform != 'linux' &&
|
||||
<Labeled label={t('Use Tsinghua Pip Mirrors')} flex spaceBetween content={
|
||||
<Switch checked={commonStore.settings.cnMirror}
|
||||
onChange={(e, data) => {
|
||||
@@ -88,14 +135,143 @@ export const Settings: FC = observer(() => {
|
||||
}} />
|
||||
} />
|
||||
}
|
||||
<Labeled label={t('API Host')} flex spaceBetween content={
|
||||
<Input value={commonStore.settings.host}
|
||||
<Labeled label={t('Allow external access to the API (service must be restarted)')} flex spaceBetween content={
|
||||
<Switch checked={commonStore.settings.host !== '127.0.0.1'}
|
||||
onChange={(e, data) => {
|
||||
commonStore.setSettings({
|
||||
host: data.value
|
||||
host: data.checked ? '0.0.0.0' : '127.0.0.1'
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Accordion collapsible openItems={!commonStore.advancedCollapsed && 'advanced'} onToggle={(e, data) => {
|
||||
if (data.value === 'advanced')
|
||||
commonStore.setAdvancedCollapsed(!commonStore.advancedCollapsed);
|
||||
}}>
|
||||
<AccordionItem value="advanced">
|
||||
<AccordionHeader ref={advancedHeaderRef} size="large">{t('Advanced')}</AccordionHeader>
|
||||
<AccordionPanel>
|
||||
<div className="flex flex-col gap-2 overflow-hidden">
|
||||
{commonStore.platform !== 'darwin' &&
|
||||
<Labeled label={t('Custom Models Path')}
|
||||
content={
|
||||
<Input className="grow" placeholder="./models" value={commonStore.settings.customModelsPath}
|
||||
onChange={(e, data) => {
|
||||
commonStore.setSettings({
|
||||
customModelsPath: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
}
|
||||
<Labeled label={t('Custom Python Path')} // if set, will not use precompiled cuda kernel
|
||||
content={
|
||||
<Input className="grow" placeholder="./py310/python" value={commonStore.settings.customPythonPath}
|
||||
onChange={(e, data) => {
|
||||
commonStore.setDepComplete(false);
|
||||
commonStore.setSettings({
|
||||
customPythonPath: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled label={'API URL'}
|
||||
content={
|
||||
<div className="flex gap-2">
|
||||
<Input style={{ minWidth: 0 }} className="grow" value={commonStore.settings.apiUrl}
|
||||
onChange={(e, data) => {
|
||||
commonStore.setSettings({
|
||||
apiUrl: data.value
|
||||
});
|
||||
}} />
|
||||
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
|
||||
value="..." selectedOptions={[]} expandIcon={null}
|
||||
onOptionSelect={(_, data) => {
|
||||
commonStore.setSettings({
|
||||
apiUrl: data.optionValue
|
||||
});
|
||||
if (data.optionText === 'OpenAI') {
|
||||
if (commonStore.settings.apiChatModelName === 'rwkv')
|
||||
commonStore.setSettings({
|
||||
apiChatModelName: 'gpt-3.5-turbo'
|
||||
});
|
||||
if (commonStore.settings.apiCompletionModelName === 'rwkv')
|
||||
commonStore.setSettings({
|
||||
apiCompletionModelName: 'text-davinci-003'
|
||||
});
|
||||
}
|
||||
}}>
|
||||
<Option value="">{t('Localhost')!}</Option>
|
||||
<Option value="https://api.openai.com">OpenAI</Option>
|
||||
</Dropdown>
|
||||
</div>
|
||||
} />
|
||||
<Labeled label={'API Key'}
|
||||
content={
|
||||
<Input className="grow" placeholder="sk-" value={commonStore.settings.apiKey}
|
||||
onChange={(e, data) => {
|
||||
commonStore.setSettings({
|
||||
apiKey: data.value
|
||||
});
|
||||
}} />
|
||||
} />
|
||||
<Labeled label={t('API Chat Model Name')}
|
||||
content={
|
||||
<div className="flex gap-2">
|
||||
<Input style={{ minWidth: 0 }} className="grow" placeholder="rwkv"
|
||||
value={commonStore.settings.apiChatModelName}
|
||||
onChange={(e, data) => {
|
||||
commonStore.setSettings({
|
||||
apiChatModelName: data.value
|
||||
});
|
||||
}} />
|
||||
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
|
||||
value="..." selectedOptions={[]} expandIcon={null}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue) {
|
||||
commonStore.setSettings({
|
||||
apiChatModelName: data.optionValue
|
||||
});
|
||||
}
|
||||
}}>
|
||||
{
|
||||
['rwkv', 'gpt-4', 'gpt-4-0613', 'gpt-4-32k', 'gpt-4-32k-0613', 'gpt-3.5-turbo', 'gpt-3.5-turbo-0613', 'gpt-3.5-turbo-16k', 'gpt-3.5-turbo-16k-0613']
|
||||
.map((v, i) =>
|
||||
<Option key={i} value={v}>{v}</Option>
|
||||
)
|
||||
}
|
||||
</Dropdown>
|
||||
</div>
|
||||
} />
|
||||
<Labeled label={t('API Completion Model Name')}
|
||||
content={
|
||||
<div className="flex gap-2">
|
||||
<Input style={{ minWidth: 0 }} className="grow" placeholder="rwkv"
|
||||
value={commonStore.settings.apiCompletionModelName}
|
||||
onChange={(e, data) => {
|
||||
commonStore.setSettings({
|
||||
apiCompletionModelName: data.value
|
||||
});
|
||||
}} />
|
||||
<Dropdown style={{ minWidth: 0 }} listbox={{ style: { minWidth: 0 } }}
|
||||
value="..." selectedOptions={[]} expandIcon={null}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionValue) {
|
||||
commonStore.setSettings({
|
||||
apiCompletionModelName: data.optionValue
|
||||
});
|
||||
}
|
||||
}}>
|
||||
{
|
||||
['rwkv', 'text-davinci-003', 'text-davinci-002', 'text-curie-001', 'text-babbage-001', 'text-ada-001']
|
||||
.map((v, i) =>
|
||||
<Option key={i} value={v}>{v}</Option>
|
||||
)
|
||||
}
|
||||
</Dropdown>
|
||||
</div>
|
||||
} />
|
||||
</div>
|
||||
</AccordionPanel>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
} />
|
||||
);
|
||||
|
||||
@@ -1,13 +1,605 @@
|
||||
import React, { FC } from 'react';
|
||||
import { Text } from '@fluentui/react-components';
|
||||
import React, { FC, ReactElement, useEffect, useRef, useState } from 'react';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button, Dropdown, Input, Option, Select, Switch, Tab, TabList } from '@fluentui/react-components';
|
||||
import {
|
||||
ConvertData,
|
||||
FileExists,
|
||||
GetPyError,
|
||||
MergeLora,
|
||||
OpenFileFolder,
|
||||
WslCommand,
|
||||
WslEnable,
|
||||
WslInstallUbuntu,
|
||||
WslIsEnabled,
|
||||
WslStart,
|
||||
WslStop
|
||||
} from '../../wailsjs/go/backend_golang/App';
|
||||
import { toast } from 'react-toastify';
|
||||
import commonStore from '../stores/commonStore';
|
||||
import { observer } from 'mobx-react-lite';
|
||||
import { SelectTabEventHandler } from '@fluentui/react-tabs';
|
||||
import { checkDependencies, toastWithButton } from '../utils';
|
||||
import { Section } from '../components/Section';
|
||||
import { Labeled } from '../components/Labeled';
|
||||
import { ToolTipButton } from '../components/ToolTipButton';
|
||||
import { DataUsageSettings20Regular, Folder20Regular } from '@fluentui/react-icons';
|
||||
import { useNavigate } from 'react-router';
|
||||
import { Precision } from './Configs';
|
||||
import {
|
||||
CategoryScale,
|
||||
Chart as ChartJS,
|
||||
Legend,
|
||||
LinearScale,
|
||||
LineElement,
|
||||
PointElement,
|
||||
Title,
|
||||
Tooltip
|
||||
} from 'chart.js';
|
||||
import { Line } from 'react-chartjs-2';
|
||||
import { ChartJSOrUndefined } from 'react-chartjs-2/dist/types';
|
||||
import { WindowShow } from '../../wailsjs/runtime';
|
||||
import { t } from 'i18next';
|
||||
import { DialogButton } from '../components/DialogButton';
|
||||
|
||||
ChartJS.register(
|
||||
CategoryScale,
|
||||
LinearScale,
|
||||
PointElement,
|
||||
LineElement,
|
||||
Tooltip,
|
||||
Title,
|
||||
Legend
|
||||
);
|
||||
|
||||
const parseLossData = (data: string) => {
|
||||
const regex = /Epoch (\d+):\s+(\d+%)\|[\s\S]*\| (\d+)\/(\d+) \[(\d+:\d+)<(\d+:\d+),\s+([\S]*), loss=(\S+),[\s\S]*\]/g;
|
||||
const matches = Array.from(data.matchAll(regex));
|
||||
if (matches.length === 0)
|
||||
return false;
|
||||
const lastMatch = matches[matches.length - 1];
|
||||
const epoch = parseInt(lastMatch[1]);
|
||||
const loss = parseFloat(lastMatch[8]);
|
||||
commonStore.setChartTitle(`Epoch ${epoch}: ${lastMatch[2]} - ${lastMatch[3]}/${lastMatch[4]} - ${lastMatch[5]}/${lastMatch[6]} - ${lastMatch[7]} Loss=${loss}`);
|
||||
addLossDataToChart(epoch, loss);
|
||||
return true;
|
||||
};
|
||||
|
||||
let chartLine: ChartJSOrUndefined<'line', (number | null)[], string>;
|
||||
|
||||
const addLossDataToChart = (epoch: number, loss: number) => {
|
||||
const epochIndex = commonStore.chartData.labels!.findIndex(l => l.includes(epoch.toString()));
|
||||
if (epochIndex === -1) {
|
||||
if (epoch === 0) {
|
||||
commonStore.chartData.labels!.push('Init');
|
||||
commonStore.chartData.datasets[0].data = [...commonStore.chartData.datasets[0].data, loss];
|
||||
}
|
||||
commonStore.chartData.labels!.push('Epoch ' + epoch.toString());
|
||||
commonStore.chartData.datasets[0].data = [...commonStore.chartData.datasets[0].data, loss];
|
||||
} else {
|
||||
if (chartLine) {
|
||||
const newData = [...commonStore.chartData.datasets[0].data];
|
||||
newData[epochIndex] = loss;
|
||||
chartLine.data.datasets[0].data = newData;
|
||||
chartLine.update();
|
||||
}
|
||||
}
|
||||
commonStore.setChartData(commonStore.chartData);
|
||||
};
|
||||
|
||||
export type DataProcessParameters = {
|
||||
dataPath: string;
|
||||
vocabPath: string;
|
||||
}
|
||||
|
||||
export type LoraFinetunePrecision = 'bf16' | 'fp16' | 'fp32' | 'tf32';
|
||||
|
||||
export type LoraFinetuneParameters = {
|
||||
baseModel: string;
|
||||
ctxLen: number;
|
||||
epochSteps: number;
|
||||
epochCount: number;
|
||||
epochBegin: number;
|
||||
epochSave: number;
|
||||
microBsz: number;
|
||||
accumGradBatches: number;
|
||||
preFfn: boolean;
|
||||
headQk: boolean;
|
||||
lrInit: string;
|
||||
lrFinal: string;
|
||||
warmupSteps: number;
|
||||
beta1: number;
|
||||
beta2: number;
|
||||
adamEps: string;
|
||||
devices: number;
|
||||
precision: LoraFinetunePrecision;
|
||||
gradCp: boolean;
|
||||
loraR: number;
|
||||
loraAlpha: number;
|
||||
loraDropout: number;
|
||||
loraLoad: string
|
||||
}
|
||||
|
||||
const loraFinetuneParametersOptions: Array<[key: keyof LoraFinetuneParameters, type: string, name: string]> = [
|
||||
['devices', 'number', 'Devices'],
|
||||
['precision', 'LoraFinetunePrecision', 'Precision'],
|
||||
['gradCp', 'boolean', 'Gradient Checkpoint'],
|
||||
['ctxLen', 'number', 'Context Length'],
|
||||
['epochSteps', 'number', 'Epoch Steps'],
|
||||
['epochCount', 'number', 'Epoch Count'],
|
||||
['epochBegin', 'number', 'Epoch Begin'],
|
||||
['epochSave', 'number', 'Epoch Save'],
|
||||
['lrInit', 'string', 'Learning Rate Init'],
|
||||
['lrFinal', 'string', 'Learning Rate Final'],
|
||||
['microBsz', 'number', 'Micro Batch Size'],
|
||||
['accumGradBatches', 'number', 'Accumulate Gradient Batches'],
|
||||
['warmupSteps', 'number', 'Warmup Steps'],
|
||||
['adamEps', 'string', 'Adam Epsilon'],
|
||||
['beta1', 'number', 'Beta 1'],
|
||||
['beta2', 'number', 'Beta 2'],
|
||||
['loraR', 'number', 'LoRA R'],
|
||||
['loraAlpha', 'number', 'LoRA Alpha'],
|
||||
['loraDropout', 'number', 'LoRA Dropout'],
|
||||
['beta1', 'any', ''],
|
||||
['preFfn', 'boolean', 'Pre-FFN'],
|
||||
['headQk', 'boolean', 'Head QK']
|
||||
];
|
||||
|
||||
const showError = (e: any) => {
|
||||
const msg = e.message || e;
|
||||
if (msg === 'wsl not running') {
|
||||
toast(t('WSL is not running, please retry. If it keeps happening, it means you may be using an outdated version of WSL, run "wsl --update" to update.'), { type: 'error' });
|
||||
} else {
|
||||
toast(t(msg), { type: 'error', toastId: 'train_error' });
|
||||
}
|
||||
};
|
||||
|
||||
const errorsMap = Object.entries({
|
||||
'python3 ./finetune/lora/train.py': 'Memory is not enough, try to increase the virtual memory or use a smaller base model.',
|
||||
'cuda out of memory': 'VRAM is not enough',
|
||||
'valueerror: high <= 0': 'Training data is not enough, reduce context length or add more data for training',
|
||||
'+= \'+ptx\'': 'You are using WSL 1 for training, please upgrade to WSL 2. e.g. Run "wsl --set-version Ubuntu-22.04 2"',
|
||||
'size mismatch for blocks': 'Size mismatch for blocks. You are attempting to continue training from the LoRA model, but it does not match the base model. Please set LoRA model to None.',
|
||||
'cuda_home environment variable is not set': 'Matched CUDA is not installed',
|
||||
'unsupported gpu architecture': 'Matched CUDA is not installed',
|
||||
'error building extension \'fused_adam\'': 'Matched CUDA is not installed'
|
||||
});
|
||||
|
||||
export const wslHandler = (data: string) => {
|
||||
if (data) {
|
||||
addWslMessage(data);
|
||||
const ok = parseLossData(data);
|
||||
if (!ok)
|
||||
for (const [key, value] of errorsMap) {
|
||||
if (data.toLowerCase().includes(key)) {
|
||||
showError(value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const addWslMessage = (message: string) => {
|
||||
const newData = commonStore.wslStdout + '\n' + message;
|
||||
let lines = newData.split('\n');
|
||||
const result = lines.slice(-100).join('\n');
|
||||
commonStore.setWslStdout(result);
|
||||
};
|
||||
|
||||
const TerminalDisplay: FC = observer(() => {
|
||||
const bodyRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const scrollToBottom = () => {
|
||||
if (bodyRef.current)
|
||||
bodyRef.current.scrollTop = bodyRef.current.scrollHeight;
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
scrollToBottom();
|
||||
});
|
||||
|
||||
return (
|
||||
<div ref={bodyRef} className="grow overflow-x-hidden overflow-y-auto border-gray-500 border-2 rounded-md">
|
||||
<div className="whitespace-pre-line">
|
||||
{commonStore.wslStdout}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
const Terminal: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
const [input, setInput] = useState('');
|
||||
|
||||
const handleKeyDown = (e: any) => {
|
||||
e.stopPropagation();
|
||||
if (e.keyCode === 13) {
|
||||
e.preventDefault();
|
||||
if (!input) return;
|
||||
|
||||
WslStart().then(() => {
|
||||
addWslMessage('WSL> ' + input);
|
||||
setInput('');
|
||||
WslCommand(input).catch(showError);
|
||||
}).catch(showError);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full gap-4">
|
||||
<TerminalDisplay />
|
||||
<div className="flex gap-2 items-center">
|
||||
WSL:
|
||||
<Input className="grow" value={input} onChange={(e) => {
|
||||
setInput(e.target.value);
|
||||
}} onKeyDown={handleKeyDown}></Input>
|
||||
<Button onClick={() => {
|
||||
WslStop().then(() => {
|
||||
toast(t('Command Stopped'), { type: 'success' });
|
||||
}).catch(showError);
|
||||
}}>
|
||||
{t('Stop')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
const LoraFinetune: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
const navigate = useNavigate();
|
||||
const chartRef = useRef<ChartJSOrUndefined<'line', (number | null)[], string>>(null);
|
||||
|
||||
const dataParams = commonStore.dataProcessParams;
|
||||
const loraParams = commonStore.loraFinetuneParams;
|
||||
|
||||
if (chartRef.current)
|
||||
chartLine = chartRef.current;
|
||||
|
||||
const setDataParams = (newParams: Partial<DataProcessParameters>) => {
|
||||
commonStore.setDataProcessParams({
|
||||
...dataParams,
|
||||
...newParams
|
||||
});
|
||||
};
|
||||
|
||||
const setLoraParams = (newParams: Partial<LoraFinetuneParameters>) => {
|
||||
commonStore.setLoraFinetuneParameters({
|
||||
...loraParams,
|
||||
...newParams
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (loraParams.baseModel === '')
|
||||
setLoraParams({
|
||||
baseModel: commonStore.modelSourceList.find(m => m.isComplete)?.name || ''
|
||||
});
|
||||
}, []);
|
||||
|
||||
const StartLoraFinetune = async () => {
|
||||
const ok = await checkDependencies(navigate);
|
||||
if (!ok)
|
||||
return;
|
||||
|
||||
const convertedDataPath = `./finetune/json2binidx_tool/data/${dataParams.dataPath.split(/[\/\\]/).pop()!.split('.')[0]}_text_document`;
|
||||
if (!await FileExists(convertedDataPath + '.idx')) {
|
||||
toast(t('Please convert data first.'), { type: 'error' });
|
||||
return;
|
||||
}
|
||||
|
||||
WslIsEnabled().then(() => {
|
||||
WslStart().then(() => {
|
||||
setTimeout(WindowShow, 1000);
|
||||
|
||||
let ctxLen = loraParams.ctxLen;
|
||||
if (dataParams.dataPath === 'finetune/data/sample.jsonl') {
|
||||
ctxLen = 150;
|
||||
toast(t('You are using sample data for training. For formal training, please make sure to create your own jsonl file.'), {
|
||||
type: 'info',
|
||||
autoClose: 6000
|
||||
});
|
||||
}
|
||||
|
||||
commonStore.setChartData({
|
||||
labels: [],
|
||||
datasets: [
|
||||
{
|
||||
label: 'Loss',
|
||||
data: [],
|
||||
borderColor: 'rgb(53, 162, 235)',
|
||||
backgroundColor: 'rgba(53, 162, 235, 0.5)'
|
||||
}
|
||||
]
|
||||
});
|
||||
WslCommand(`export cnMirror=${commonStore.settings.cnMirror ? '1' : '0'} ` +
|
||||
`&& export loadModel=models/${loraParams.baseModel} ` +
|
||||
`&& sed -i 's/\\r$//' finetune/install-wsl-dep-and-train.sh ` +
|
||||
`&& chmod +x finetune/install-wsl-dep-and-train.sh && ./finetune/install-wsl-dep-and-train.sh ` +
|
||||
(loraParams.baseModel ? `--load_model models/${loraParams.baseModel} ` : '') +
|
||||
(loraParams.loraLoad ? `--lora_load lora-models/${loraParams.loraLoad} ` : '') +
|
||||
`--data_file ${convertedDataPath} ` +
|
||||
`--vocab_size ${loraParams.baseModel.toLowerCase().includes('world') ? '65536' : '50277'} ` +
|
||||
`--ctx_len ${ctxLen} --epoch_steps ${loraParams.epochSteps} --epoch_count ${loraParams.epochCount} ` +
|
||||
`--epoch_begin ${loraParams.epochBegin} --epoch_save ${loraParams.epochSave} ` +
|
||||
`--micro_bsz ${loraParams.microBsz} --accumulate_grad_batches ${loraParams.accumGradBatches} ` +
|
||||
`--pre_ffn ${loraParams.preFfn ? '1' : '0'} --head_qk ${loraParams.headQk ? '1' : '0'} --lr_init ${loraParams.lrInit} --lr_final ${loraParams.lrFinal} ` +
|
||||
`--warmup_steps ${loraParams.warmupSteps} ` +
|
||||
`--beta1 ${loraParams.beta1} --beta2 ${loraParams.beta2} --adam_eps ${loraParams.adamEps} ` +
|
||||
`--devices ${loraParams.devices} --precision ${loraParams.precision} ` +
|
||||
`--grad_cp ${loraParams.gradCp ? '1' : '0'} ` +
|
||||
`--lora_r ${loraParams.loraR} --lora_alpha ${loraParams.loraAlpha} --lora_dropout ${loraParams.loraDropout}`).catch(showError);
|
||||
}).catch(e => {
|
||||
const msg = e.message || e;
|
||||
if (msg === 'ubuntu not found') {
|
||||
WindowShow();
|
||||
toastWithButton(t('Ubuntu is not installed, do you want to install it?'), t('Install Ubuntu'), () => {
|
||||
WslInstallUbuntu().then(() => {
|
||||
WindowShow();
|
||||
toast(t('Please install Ubuntu using Microsoft Store, after installation click the Open button in Microsoft Store and then click the Train button'), {
|
||||
type: 'info',
|
||||
autoClose: 10000
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}).catch(e => {
|
||||
const msg = e.message || e;
|
||||
|
||||
const enableWsl = (forceMode: boolean) => {
|
||||
WindowShow();
|
||||
toastWithButton(t('WSL is not enabled, do you want to enable it?'), t('Enable WSL'), () => {
|
||||
WslEnable(forceMode).then(() => {
|
||||
WindowShow();
|
||||
toast(t('After installation, please restart your computer to enable WSL'), {
|
||||
type: 'info',
|
||||
autoClose: false
|
||||
});
|
||||
}).catch(showError);
|
||||
});
|
||||
};
|
||||
|
||||
if (msg === 'wsl is not enabled') {
|
||||
enableWsl(false);
|
||||
} else if (msg.includes('wsl.state: The system cannot find the file')) {
|
||||
enableWsl(true);
|
||||
} else {
|
||||
showError(msg);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex flex-col h-full w-full gap-2">
|
||||
{(commonStore.wslStdout.length > 0 || commonStore.chartData.labels!.length !== 0) &&
|
||||
<div className="flex" style={{ height: '35%' }}>
|
||||
{commonStore.wslStdout.length > 0 && commonStore.chartData.labels!.length === 0 && <TerminalDisplay />}
|
||||
{commonStore.chartData.labels!.length !== 0 &&
|
||||
<Line ref={chartRef} data={commonStore.chartData} options={{
|
||||
responsive: true,
|
||||
showLine: true,
|
||||
plugins: {
|
||||
legend: {
|
||||
position: 'right',
|
||||
align: 'start'
|
||||
},
|
||||
title: {
|
||||
display: true,
|
||||
text: commonStore.chartTitle
|
||||
}
|
||||
},
|
||||
scales: {
|
||||
y: {
|
||||
beginAtZero: true
|
||||
}
|
||||
},
|
||||
maintainAspectRatio: false
|
||||
}} style={{ width: '100%' }} />}
|
||||
</div>
|
||||
}
|
||||
<div>
|
||||
<Section
|
||||
title={t('Data Process')}
|
||||
content={
|
||||
<div className="flex flex-col gap-2">
|
||||
<div className="flex gap-2 items-center">
|
||||
{t('Data Path')}
|
||||
<Input className="grow" style={{ minWidth: 0 }} value={dataParams.dataPath}
|
||||
onChange={(e, data) => {
|
||||
setDataParams({ dataPath: data.value });
|
||||
}} />
|
||||
<DialogButton text={t('Help')} title={t('Help')} markdown
|
||||
contentText={t('The data path should be a directory or a file in jsonl format (more formats will be supported in the future).\n\n' +
|
||||
'When you provide a directory path, all the txt files within that directory will be automatically converted into training data. ' +
|
||||
'This is commonly used for large-scale training in writing, code generation, or knowledge bases.\n\n' +
|
||||
'The jsonl format file can be referenced at https://github.com/Abel2076/json2binidx_tool/blob/main/sample.jsonl.\n' +
|
||||
'You can also write it similar to OpenAI\'s playground format, as shown in https://platform.openai.com/playground/p/default-chat.\n' +
|
||||
'Even for multi-turn conversations, they must be written in a single line using `\\n` to indicate line breaks. ' +
|
||||
'If they are different dialogues or topics, they should be written in separate lines.')} />
|
||||
<ToolTipButton desc={t('Open Folder')} icon={<Folder20Regular />} onClick={() => {
|
||||
OpenFileFolder(dataParams.dataPath, false);
|
||||
}} />
|
||||
</div>
|
||||
<div className="flex gap-2 items-center">
|
||||
{t('Vocab Path')}
|
||||
<Input className="grow" style={{ minWidth: 0 }} value={dataParams.vocabPath}
|
||||
onChange={(e, data) => {
|
||||
setDataParams({ vocabPath: data.value });
|
||||
}} />
|
||||
<Button appearance="secondary" onClick={async () => {
|
||||
const ok = await checkDependencies(navigate);
|
||||
if (!ok)
|
||||
return;
|
||||
const outputPrefix = './finetune/json2binidx_tool/data/' +
|
||||
dataParams.dataPath.replace(/[\/\\]$/, '').split(/[\/\\]/).pop()!.split('.')[0];
|
||||
ConvertData(commonStore.settings.customPythonPath, dataParams.dataPath, outputPrefix, dataParams.vocabPath).then(async () => {
|
||||
if (!await FileExists(outputPrefix + '_text_document.idx')) {
|
||||
toast(t('Failed to convert data') + ' - ' + await GetPyError(), { type: 'error' });
|
||||
} else {
|
||||
toast(t('Convert Data successfully'), { type: 'success' });
|
||||
}
|
||||
}).catch(showError);
|
||||
}}>{t('Convert')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
<Section
|
||||
title={t('Train Parameters')}
|
||||
content={
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-2">
|
||||
<div className="flex gap-2 items-center">
|
||||
{t('Base Model')}
|
||||
<Select style={{ minWidth: 0 }} className="grow"
|
||||
value={loraParams.baseModel}
|
||||
onChange={(e, data) => {
|
||||
setLoraParams({
|
||||
baseModel: data.value
|
||||
});
|
||||
}}>
|
||||
{commonStore.modelSourceList.map((modelItem, index) =>
|
||||
modelItem.isComplete && <option key={index} value={modelItem.name}>{modelItem.name}</option>
|
||||
)}
|
||||
</Select>
|
||||
<ToolTipButton desc={t('Manage Models')} icon={<DataUsageSettings20Regular />} onClick={() => {
|
||||
navigate({ pathname: '/models' });
|
||||
}} />
|
||||
</div>
|
||||
<div className="flex gap-2 items-center">
|
||||
{t('LoRA Model')}
|
||||
<Select style={{ minWidth: 0 }} className="grow"
|
||||
value={loraParams.loraLoad}
|
||||
onChange={(e, data) => {
|
||||
setLoraParams({
|
||||
loraLoad: data.value
|
||||
});
|
||||
}}>
|
||||
<option value="">{t('None')}</option>
|
||||
{commonStore.loraModels.map((name, index) =>
|
||||
<option key={index} value={name}>{name}</option>
|
||||
)}
|
||||
</Select>
|
||||
<Button onClick={async () => {
|
||||
const ok = await checkDependencies(navigate);
|
||||
if (!ok)
|
||||
return;
|
||||
if (loraParams.loraLoad) {
|
||||
const outputPath = `models/${loraParams.baseModel}-LoRA-${loraParams.loraLoad}`;
|
||||
MergeLora(commonStore.settings.customPythonPath, true, loraParams.loraAlpha,
|
||||
'models/' + loraParams.baseModel, 'lora-models/' + loraParams.loraLoad,
|
||||
outputPath).then(async () => {
|
||||
if (!await FileExists(outputPath)) {
|
||||
toast(t('Failed to merge model') + ' - ' + await GetPyError(), { type: 'error' });
|
||||
} else {
|
||||
toast(t('Merge model successfully'), { type: 'success' });
|
||||
}
|
||||
}).catch(showError);
|
||||
} else {
|
||||
toast(t('Please select a LoRA model'), { type: 'info' });
|
||||
}
|
||||
}}>{t('Merge Model')}</Button>
|
||||
</div>
|
||||
{
|
||||
loraFinetuneParametersOptions.map(([key, type, name], index) => {
|
||||
return (
|
||||
<Labeled key={index} label={t(name)} content={
|
||||
type === 'number' ?
|
||||
<Input type="number" className="grow" value={loraParams[key].toString()}
|
||||
onChange={(e, data) => {
|
||||
setLoraParams({
|
||||
[key]: Number(data.value)
|
||||
});
|
||||
}} /> :
|
||||
type === 'boolean' ?
|
||||
<Switch className="grow" checked={loraParams[key] as boolean}
|
||||
onChange={(e, data) => {
|
||||
setLoraParams({
|
||||
[key]: data.checked
|
||||
});
|
||||
}} /> :
|
||||
type === 'string' ?
|
||||
<Input className="grow" value={loraParams[key].toString()}
|
||||
onChange={(e, data) => {
|
||||
setLoraParams({
|
||||
[key]: data.value
|
||||
});
|
||||
}} /> :
|
||||
type === 'LoraFinetunePrecision' ?
|
||||
<Dropdown style={{ minWidth: 0 }} className="grow"
|
||||
value={loraParams[key].toString()}
|
||||
selectedOptions={[loraParams[key].toString()]}
|
||||
onOptionSelect={(_, data) => {
|
||||
if (data.optionText) {
|
||||
setLoraParams({
|
||||
precision: data.optionText as LoraFinetunePrecision
|
||||
});
|
||||
}
|
||||
}}
|
||||
>
|
||||
<Option>bf16</Option>
|
||||
<Option>fp16</Option>
|
||||
<Option>fp32</Option>
|
||||
<Option>tf32</Option>
|
||||
</Dropdown>
|
||||
: <div />
|
||||
} />
|
||||
);
|
||||
})
|
||||
}
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
<div className="grow" />
|
||||
<div className="flex gap-2">
|
||||
<div className="grow" />
|
||||
<Button appearance="secondary" size="large" onClick={() => {
|
||||
WslStop().then(() => {
|
||||
toast(t('Command Stopped'), { type: 'success' });
|
||||
}).catch(showError);
|
||||
}}>{t('Stop')}</Button>
|
||||
<Button appearance="primary" size="large" onClick={StartLoraFinetune}>{t('Train')}</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
type TrainNavigationItem = {
|
||||
element: ReactElement;
|
||||
};
|
||||
|
||||
const pages: { [label: string]: TrainNavigationItem } = {
|
||||
'LoRA Finetune': {
|
||||
element: <LoraFinetune />
|
||||
},
|
||||
WSL: {
|
||||
element: <Terminal />
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
export const Train: FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const [tab, setTab] = useState('LoRA Finetune');
|
||||
|
||||
return (
|
||||
<div className="flex flex-col box-border gap-5 p-2">
|
||||
<Text size={600}>{t('In Development')}</Text>
|
||||
const selectTab: SelectTabEventHandler = (e, data) =>
|
||||
typeof data.value === 'string' ? setTab(data.value) : null;
|
||||
|
||||
return <div className="flex flex-col gap-2 w-full h-full">
|
||||
<TabList
|
||||
size="small"
|
||||
appearance="subtle"
|
||||
selectedValue={tab}
|
||||
onTabSelect={selectTab}
|
||||
>
|
||||
{Object.entries(pages).map(([label]) => (
|
||||
<Tab key={label} value={label}>
|
||||
{t(label)}
|
||||
</Tab>
|
||||
))}
|
||||
</TabList>
|
||||
<div className="grow overflow-hidden">
|
||||
{pages[tab].element}
|
||||
</div>
|
||||
);
|
||||
</div>;
|
||||
};
|
||||
|
||||
1127
frontend/src/pages/defaultModelConfigs.ts
Normal file
@@ -1,38 +1,37 @@
|
||||
import commonStore from './stores/commonStore';
|
||||
import { FileExists, ReadJson } from '../wailsjs/go/backend_golang/App';
|
||||
import {
|
||||
Cache,
|
||||
checkUpdate,
|
||||
downloadProgramFiles,
|
||||
forceDownloadProgramFiles,
|
||||
LocalConfig,
|
||||
refreshModels,
|
||||
saveCache
|
||||
} from './utils';
|
||||
import commonStore, { Platform } from './stores/commonStore';
|
||||
import { GetPlatform, ListDirFiles, ReadJson } from '../wailsjs/go/backend_golang/App';
|
||||
import { Cache, checkUpdate, downloadProgramFiles, LocalConfig, refreshLocalModels, refreshModels } from './utils';
|
||||
import { getStatus } from './apis';
|
||||
import { EventsOn } from '../wailsjs/runtime';
|
||||
import { defaultModelConfigs } from './pages/Configs';
|
||||
import manifest from '../../manifest.json';
|
||||
import { defaultModelConfigs, defaultModelConfigsMac } from './pages/defaultModelConfigs';
|
||||
import { Preset } from './pages/PresetsManager/PresetsButton';
|
||||
import { wslHandler } from './pages/Train';
|
||||
|
||||
export async function startup() {
|
||||
FileExists('cache.json').then((exists) => {
|
||||
if (exists)
|
||||
downloadProgramFiles();
|
||||
else
|
||||
forceDownloadProgramFiles();
|
||||
});
|
||||
downloadProgramFiles();
|
||||
EventsOn('downloadList', (data) => {
|
||||
if (data)
|
||||
commonStore.setDownloadList(data);
|
||||
});
|
||||
EventsOn('wsl', wslHandler);
|
||||
EventsOn('wslerr', (e) => {
|
||||
console.log(e);
|
||||
});
|
||||
initLocalModelsNotify();
|
||||
initLoraModels();
|
||||
|
||||
initCache().then(initRemoteText);
|
||||
initPresets();
|
||||
|
||||
await GetPlatform().then(p => commonStore.setPlatform(p as Platform));
|
||||
await initConfig();
|
||||
|
||||
initCache(true).then(initRemoteText); // depends on config customModelsPath
|
||||
|
||||
if (commonStore.settings.autoUpdatesCheck) // depends on config settings
|
||||
checkUpdate();
|
||||
|
||||
getStatus(500).then(status => { // depends on config api port
|
||||
getStatus(1000).then(status => { // depends on config api port
|
||||
if (status)
|
||||
commonStore.setStatus(status);
|
||||
});
|
||||
@@ -41,11 +40,13 @@ export async function startup() {
|
||||
async function initRemoteText() {
|
||||
await fetch('https://cdn.jsdelivr.net/gh/josstorer/RWKV-Runner@master/manifest.json', { cache: 'no-cache' })
|
||||
.then(r => r.json()).then((data) => {
|
||||
if (data.introduction)
|
||||
commonStore.setIntroduction(data.introduction);
|
||||
if (data.about)
|
||||
commonStore.setAbout(data.about);
|
||||
}).then(saveCache);
|
||||
if (data.version > manifest.version) {
|
||||
if (data.introduction)
|
||||
commonStore.setIntroduction(data.introduction);
|
||||
if (data.about)
|
||||
commonStore.setAbout(data.about);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async function initConfig() {
|
||||
@@ -56,6 +57,12 @@ async function initConfig() {
|
||||
if (configData.settings)
|
||||
commonStore.setSettings(configData.settings, false);
|
||||
|
||||
if (configData.dataProcessParams)
|
||||
commonStore.setDataProcessParams(configData.dataProcessParams, false);
|
||||
|
||||
if (configData.loraFinetuneParams)
|
||||
commonStore.setLoraFinetuneParameters(configData.loraFinetuneParams, false);
|
||||
|
||||
if (configData.modelConfigs && Array.isArray(configData.modelConfigs))
|
||||
commonStore.setModelConfigs(configData.modelConfigs, false);
|
||||
else throw new Error('Invalid config.json');
|
||||
@@ -63,19 +70,50 @@ async function initConfig() {
|
||||
configData.currentModelConfigIndex >= 0 && configData.currentModelConfigIndex < configData.modelConfigs.length)
|
||||
commonStore.setCurrentConfigIndex(configData.currentModelConfigIndex, false);
|
||||
}).catch(() => {
|
||||
commonStore.setModelConfigs(defaultModelConfigs, true);
|
||||
commonStore.setModelConfigs(commonStore.platform != 'darwin' ? defaultModelConfigs : defaultModelConfigsMac, true);
|
||||
});
|
||||
}
|
||||
|
||||
async function initCache() {
|
||||
async function initCache(initUnfinishedModels: boolean) {
|
||||
await ReadJson('cache.json').then((cacheData: Cache) => {
|
||||
if (cacheData.introduction)
|
||||
commonStore.setIntroduction(cacheData.introduction);
|
||||
if (cacheData.about)
|
||||
commonStore.setAbout(cacheData.about);
|
||||
if (cacheData.depComplete)
|
||||
commonStore.setDepComplete(cacheData.depComplete);
|
||||
if (cacheData.version === manifest.version && cacheData.depComplete)
|
||||
commonStore.setDepComplete(cacheData.depComplete, false);
|
||||
}).catch(() => {
|
||||
});
|
||||
await refreshModels(false);
|
||||
}
|
||||
await refreshModels(false, initUnfinishedModels);
|
||||
}
|
||||
|
||||
async function initPresets() {
|
||||
await ReadJson('presets.json').then((presets: Preset[]) => {
|
||||
commonStore.setPresets(presets, false);
|
||||
}).catch(() => {
|
||||
});
|
||||
}
|
||||
|
||||
async function initLoraModels() {
|
||||
const refreshLoraModels = () => {
|
||||
ListDirFiles('lora-models').then((data) => {
|
||||
if (!data) return;
|
||||
const loraModels = [];
|
||||
for (const f of data) {
|
||||
if (!f.isDir && f.name.endsWith('.pth')) {
|
||||
loraModels.push(f.name);
|
||||
}
|
||||
}
|
||||
commonStore.setLoraModels(loraModels);
|
||||
});
|
||||
};
|
||||
|
||||
refreshLoraModels();
|
||||
EventsOn('fsnotify', (data: string) => {
|
||||
if (data.includes('lora-models'))
|
||||
refreshLoraModels();
|
||||
});
|
||||
}
|
||||
|
||||
async function initLocalModelsNotify() {
|
||||
EventsOn('fsnotify', (data: string) => {
|
||||
if (data.includes('models') && !data.includes('lora-models'))
|
||||
refreshLocalModels({ models: commonStore.modelSourceList }, false); //TODO fix bug that only add models
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { makeAutoObservable } from 'mobx';
|
||||
import { getUserLanguage, isSystemLightMode, saveConfigs } from '../utils';
|
||||
import { getUserLanguage, isSystemLightMode, saveCache, saveConfigs, savePresets } from '../utils';
|
||||
import { WindowSetDarkTheme, WindowSetLightTheme } from '../../wailsjs/runtime';
|
||||
import manifest from '../../../manifest.json';
|
||||
import { defaultModelConfigs, ModelConfig } from '../pages/Configs';
|
||||
import { Conversations } from '../pages/Chat';
|
||||
import { ModelConfig } from '../pages/Configs';
|
||||
import { Conversation } from '../pages/Chat';
|
||||
import { ModelSourceItem } from '../pages/Models';
|
||||
import { DownloadStatus } from '../pages/Downloads';
|
||||
import { SettingsType } from '../pages/Settings';
|
||||
@@ -11,6 +11,11 @@ import { IntroductionContent } from '../pages/Home';
|
||||
import { AboutContent } from '../pages/About';
|
||||
import i18n from 'i18next';
|
||||
import { CompletionPreset } from '../pages/Completion';
|
||||
import { defaultModelConfigs, defaultModelConfigsMac } from '../pages/defaultModelConfigs';
|
||||
import commonStore from './commonStore';
|
||||
import { Preset } from '../pages/PresetsManager/PresetsButton';
|
||||
import { DataProcessParameters, LoraFinetuneParameters } from '../pages/Train';
|
||||
import { ChartData } from 'chart.js';
|
||||
|
||||
export enum ModelStatus {
|
||||
Offline,
|
||||
@@ -20,27 +25,38 @@ export enum ModelStatus {
|
||||
}
|
||||
|
||||
export type Status = {
|
||||
modelStatus: ModelStatus;
|
||||
status: ModelStatus;
|
||||
pid: number;
|
||||
device_name: string;
|
||||
}
|
||||
|
||||
export type Platform = 'windows' | 'darwin' | 'linux';
|
||||
|
||||
const labels = ['January', 'February', 'March', 'April', 'May', 'June', 'July'];
|
||||
|
||||
class CommonStore {
|
||||
// global
|
||||
status: Status = {
|
||||
modelStatus: ModelStatus.Offline,
|
||||
status: ModelStatus.Offline,
|
||||
pid: 0,
|
||||
device_name: 'CPU'
|
||||
};
|
||||
depComplete: boolean = false;
|
||||
platform: Platform = 'windows';
|
||||
// presets manager
|
||||
editingPreset: Preset | null = null;
|
||||
presets: Preset[] = [];
|
||||
// home
|
||||
introduction: IntroductionContent = manifest.introduction;
|
||||
// chat
|
||||
conversations: Conversations = {};
|
||||
conversationsOrder: string[] = [];
|
||||
currentInput: string = '';
|
||||
conversation: Conversation = {};
|
||||
conversationOrder: string[] = [];
|
||||
activePreset: Preset | null = null;
|
||||
// completion
|
||||
completionPreset: CompletionPreset | null = null;
|
||||
completionGenerating: boolean = false;
|
||||
completionSubmittedPrompt: string = '';
|
||||
// configs
|
||||
currentModelConfigIndex: number = 0;
|
||||
modelConfigs: ModelConfig[] = [];
|
||||
@@ -49,14 +65,57 @@ class CommonStore {
|
||||
modelSourceList: ModelSourceItem[] = [];
|
||||
// downloads
|
||||
downloadList: DownloadStatus[] = [];
|
||||
lastUnfinishedModelDownloads: DownloadStatus[] = [];
|
||||
// train
|
||||
wslStdout: string = '';
|
||||
chartTitle: string = '';
|
||||
chartData: ChartData<'line', (number | null)[], string> = { labels: [], datasets: [] };
|
||||
loraModels: string[] = [];
|
||||
dataProcessParams: DataProcessParameters = {
|
||||
dataPath: 'finetune/data/sample.jsonl',
|
||||
vocabPath: 'backend-python/rwkv_pip/rwkv_vocab_v20230424.txt'
|
||||
};
|
||||
loraFinetuneParams: LoraFinetuneParameters = {
|
||||
baseModel: '',
|
||||
ctxLen: 1024,
|
||||
epochSteps: 1000,
|
||||
epochCount: 20,
|
||||
epochBegin: 0,
|
||||
epochSave: 5,
|
||||
microBsz: 1,
|
||||
accumGradBatches: 8,
|
||||
preFfn: false,
|
||||
headQk: false,
|
||||
lrInit: '5e-5',
|
||||
lrFinal: '5e-5',
|
||||
warmupSteps: 0,
|
||||
beta1: 0.9,
|
||||
beta2: 0.999,
|
||||
adamEps: '1e-8',
|
||||
devices: 1,
|
||||
precision: 'bf16',
|
||||
gradCp: false,
|
||||
loraR: 8,
|
||||
loraAlpha: 32,
|
||||
loraDropout: 0.01,
|
||||
loraLoad: ''
|
||||
};
|
||||
// settings
|
||||
advancedCollapsed: boolean = true;
|
||||
settings: SettingsType = {
|
||||
language: getUserLanguage(),
|
||||
darkMode: !isSystemLightMode(),
|
||||
autoUpdatesCheck: true,
|
||||
giteeUpdatesSource: getUserLanguage() === 'zh',
|
||||
cnMirror: getUserLanguage() === 'zh',
|
||||
host: '127.0.0.1'
|
||||
host: '127.0.0.1',
|
||||
dpiScaling: 100,
|
||||
customModelsPath: './models',
|
||||
customPythonPath: '',
|
||||
apiUrl: '',
|
||||
apiKey: 'sk-',
|
||||
apiChatModelName: 'rwkv',
|
||||
apiCompletionModelName: 'rwkv'
|
||||
};
|
||||
// about
|
||||
about: AboutContent = manifest.about;
|
||||
@@ -86,14 +145,17 @@ class CommonStore {
|
||||
};
|
||||
|
||||
setModelConfigs = (configs: ModelConfig[], saveConfig: boolean = true) => {
|
||||
this.modelConfigs = configs;
|
||||
this.modelConfigs = JSON.parse(JSON.stringify(configs)); // deep copy
|
||||
if (saveConfig)
|
||||
saveConfigs();
|
||||
};
|
||||
|
||||
createModelConfig = (config: ModelConfig = defaultModelConfigs[0], saveConfig: boolean = true) => {
|
||||
if (config.name === defaultModelConfigs[0].name)
|
||||
if (config.name === defaultModelConfigs[0].name) {
|
||||
// deep copy
|
||||
config = JSON.parse(JSON.stringify(commonStore.platform != 'darwin' ? defaultModelConfigs[0] : defaultModelConfigsMac[0]));
|
||||
config.name = new Date().toLocaleString();
|
||||
}
|
||||
this.modelConfigs.push(config);
|
||||
if (saveConfig)
|
||||
saveConfigs();
|
||||
@@ -145,20 +207,22 @@ class CommonStore {
|
||||
this.about = value;
|
||||
};
|
||||
|
||||
setDepComplete = (value: boolean) => {
|
||||
setDepComplete = (value: boolean, inSaveCache: boolean = true) => {
|
||||
this.depComplete = value;
|
||||
if (inSaveCache)
|
||||
saveCache();
|
||||
};
|
||||
|
||||
setDownloadList = (value: DownloadStatus[]) => {
|
||||
this.downloadList = value;
|
||||
};
|
||||
|
||||
setConversations = (value: Conversations) => {
|
||||
this.conversations = value;
|
||||
setConversation = (value: Conversation) => {
|
||||
this.conversation = value;
|
||||
};
|
||||
|
||||
setConversationsOrder = (value: string[]) => {
|
||||
this.conversationsOrder = value;
|
||||
setConversationOrder = (value: string[]) => {
|
||||
this.conversationOrder = value;
|
||||
};
|
||||
|
||||
setCompletionPreset(value: CompletionPreset) {
|
||||
@@ -168,6 +232,68 @@ class CommonStore {
|
||||
setCompletionGenerating(value: boolean) {
|
||||
this.completionGenerating = value;
|
||||
}
|
||||
|
||||
setPlatform(value: Platform) {
|
||||
this.platform = value;
|
||||
}
|
||||
|
||||
setCurrentInput(value: string) {
|
||||
this.currentInput = value;
|
||||
}
|
||||
|
||||
setAdvancedCollapsed(value: boolean) {
|
||||
this.advancedCollapsed = value;
|
||||
}
|
||||
|
||||
setLastUnfinishedModelDownloads(value: DownloadStatus[]) {
|
||||
this.lastUnfinishedModelDownloads = value;
|
||||
}
|
||||
|
||||
setEditingPreset(value: Preset) {
|
||||
this.editingPreset = value;
|
||||
}
|
||||
|
||||
setPresets(value: Preset[], savePreset: boolean = true) {
|
||||
this.presets = value;
|
||||
if (savePreset)
|
||||
savePresets();
|
||||
}
|
||||
|
||||
setActivePreset(value: Preset) {
|
||||
this.activePreset = value;
|
||||
}
|
||||
|
||||
setCompletionSubmittedPrompt(value: string) {
|
||||
this.completionSubmittedPrompt = value;
|
||||
}
|
||||
|
||||
setWslStdout(value: string) {
|
||||
this.wslStdout = value;
|
||||
}
|
||||
|
||||
setDataProcessParams(value: DataProcessParameters, saveConfig: boolean = true) {
|
||||
this.dataProcessParams = value;
|
||||
if (saveConfig)
|
||||
saveConfigs();
|
||||
}
|
||||
|
||||
setLoraFinetuneParameters(value: LoraFinetuneParameters, saveConfig: boolean = true) {
|
||||
this.loraFinetuneParams = value;
|
||||
if (saveConfig)
|
||||
saveConfigs();
|
||||
}
|
||||
|
||||
setChartTitle(value: string) {
|
||||
this.chartTitle = value;
|
||||
}
|
||||
|
||||
setChartData(value: ChartData<'line', (number | null)[], string>) {
|
||||
this.chartData = value;
|
||||
}
|
||||
|
||||
setLoraModels(value: string[]) {
|
||||
this.loraModels = value;
|
||||
}
|
||||
}
|
||||
|
||||
export default new CommonStore();
|
||||
@@ -1,27 +0,0 @@
|
||||
export type Record = {
|
||||
question: string;
|
||||
answer: string;
|
||||
}
|
||||
|
||||
export type ConversationPair = {
|
||||
role: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export function getConversationPairs(records: Record[], isCompletion: boolean): string | ConversationPair[] {
|
||||
let pairs;
|
||||
if (isCompletion) {
|
||||
pairs = '';
|
||||
for (const record of records) {
|
||||
pairs += 'Human: ' + record.question + '\nAI: ' + record.answer + '\n';
|
||||
}
|
||||
} else {
|
||||
pairs = [];
|
||||
for (const record of records) {
|
||||
pairs.push({ role: 'user', content: record.question });
|
||||
pairs.push({ role: 'assistant', content: record.answer });
|
||||
}
|
||||
}
|
||||
|
||||
return pairs;
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
import {
|
||||
AddToDownloadList,
|
||||
CopyFile,
|
||||
DeleteFile,
|
||||
FileExists,
|
||||
DepCheck,
|
||||
InstallPyDep,
|
||||
ListDirFiles,
|
||||
ReadFileInfo,
|
||||
ReadJson,
|
||||
SaveJson,
|
||||
UpdateApp
|
||||
} from '../../wailsjs/go/backend_golang/App';
|
||||
import manifest from '../../../manifest.json';
|
||||
import commonStore from '../stores/commonStore';
|
||||
import commonStore, { ModelStatus } from '../stores/commonStore';
|
||||
import { toast } from 'react-toastify';
|
||||
import { t } from 'i18next';
|
||||
import { ToastOptions } from 'react-toastify/dist/types';
|
||||
@@ -16,13 +19,14 @@ import { Button } from '@fluentui/react-components';
|
||||
import { Language, Languages, SettingsType } from '../pages/Settings';
|
||||
import { ModelSourceItem } from '../pages/Models';
|
||||
import { ModelConfig, ModelParameters } from '../pages/Configs';
|
||||
import { IntroductionContent } from '../pages/Home';
|
||||
import { AboutContent } from '../pages/About';
|
||||
import { DownloadStatus } from '../pages/Downloads';
|
||||
import { DataProcessParameters, LoraFinetuneParameters } from '../pages/Train';
|
||||
import { BrowserOpenURL, WindowShow } from '../../wailsjs/runtime';
|
||||
import { NavigateFunction } from 'react-router';
|
||||
|
||||
export type Cache = {
|
||||
version: string
|
||||
models: ModelSourceItem[]
|
||||
introduction: IntroductionContent,
|
||||
about: AboutContent
|
||||
depComplete: boolean
|
||||
}
|
||||
|
||||
@@ -30,7 +34,9 @@ export type LocalConfig = {
|
||||
modelSourceManifestList: string
|
||||
currentModelConfigIndex: number
|
||||
modelConfigs: ModelConfig[]
|
||||
settings: SettingsType
|
||||
settings: SettingsType,
|
||||
dataProcessParams: DataProcessParameters,
|
||||
loraFinetuneParams: LoraFinetuneParameters
|
||||
}
|
||||
|
||||
export async function refreshBuiltInModels(readCache: boolean = false) {
|
||||
@@ -51,19 +57,22 @@ export async function refreshBuiltInModels(readCache: boolean = false) {
|
||||
return cache;
|
||||
}
|
||||
|
||||
export async function refreshLocalModels(cache: { models: ModelSourceItem[] }, filter: boolean = true) {
|
||||
export async function refreshLocalModels(cache: {
|
||||
models: ModelSourceItem[]
|
||||
}, filter: boolean = true, initUnfinishedModels: boolean = false) {
|
||||
if (filter)
|
||||
cache.models = cache.models.filter(m => !m.isLocal); //TODO BUG cause local but in manifest files to be removed, so currently cache is disabled
|
||||
cache.models = cache.models.filter(m => !m.isComplete); //TODO BUG cause local but in manifest files to be removed, so currently cache is disabled
|
||||
|
||||
await ListDirFiles(manifest.localModelDir).then((data) => {
|
||||
await ListDirFiles(commonStore.settings.customModelsPath).then((data) => {
|
||||
cache.models.push(...data.flatMap(d => {
|
||||
if (!d.isDir && d.name.endsWith('.pth'))
|
||||
return [{
|
||||
name: d.name,
|
||||
size: d.size,
|
||||
lastUpdated: d.modTime,
|
||||
isComplete: true,
|
||||
isLocal: true
|
||||
}];
|
||||
}] as ModelSourceItem[];
|
||||
return [];
|
||||
}));
|
||||
}).catch(() => {
|
||||
@@ -84,17 +93,43 @@ export async function refreshLocalModels(cache: { models: ModelSourceItem[] }, f
|
||||
} else {
|
||||
cache.models[i] = Object.assign({}, cache.models[j], cache.models[i]);
|
||||
}
|
||||
} // else is bad local file
|
||||
} // else is not complete local file
|
||||
cache.models[i].isLocal = true;
|
||||
cache.models[i].localSize = cache.models[j].size;
|
||||
cache.models.splice(j, 1);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
commonStore.setModelSourceList(cache.models);
|
||||
if (initUnfinishedModels)
|
||||
initLastUnfinishedModelDownloads();
|
||||
await saveCache().catch(() => {
|
||||
});
|
||||
}
|
||||
|
||||
function initLastUnfinishedModelDownloads() {
|
||||
const list: DownloadStatus[] = [];
|
||||
commonStore.modelSourceList.forEach((item) => {
|
||||
if (item.isLocal && !item.isComplete) {
|
||||
list.push(
|
||||
{
|
||||
name: item.name,
|
||||
path: `${commonStore.settings.customModelsPath}/${item.name}`,
|
||||
url: item.downloadUrl!,
|
||||
transferred: item.localSize!,
|
||||
size: item.size,
|
||||
speed: 0,
|
||||
progress: item.localSize! / item.size * 100,
|
||||
downloading: false,
|
||||
done: false
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
commonStore.setLastUnfinishedModelDownloads(list);
|
||||
}
|
||||
|
||||
export async function refreshRemoteModels(cache: { models: ModelSourceItem[] }) {
|
||||
const manifestUrls = commonStore.modelSourceManifestList.split(/[,,;;\n]/);
|
||||
const requests = manifestUrls.filter(url => url.endsWith('.json')).map(
|
||||
@@ -113,16 +148,16 @@ export async function refreshRemoteModels(cache: { models: ModelSourceItem[] })
|
||||
cache.models = cache.models.filter((model, index, self) => {
|
||||
return model.name.endsWith('.pth')
|
||||
&& index === self.findIndex(
|
||||
m => m.name === model.name || (m.SHA256 === model.SHA256 && m.size === model.size));
|
||||
m => m.name === model.name || (m.SHA256 && m.SHA256 === model.SHA256 && m.size === model.size));
|
||||
});
|
||||
commonStore.setModelSourceList(cache.models);
|
||||
await saveCache().catch(() => {
|
||||
});
|
||||
}
|
||||
|
||||
export const refreshModels = async (readCache: boolean = false) => {
|
||||
export const refreshModels = async (readCache: boolean = false, initUnfinishedModels: boolean = false) => {
|
||||
const cache = await refreshBuiltInModels(readCache);
|
||||
await refreshLocalModels(cache);
|
||||
await refreshLocalModels(cache, false, initUnfinishedModels);
|
||||
await refreshRemoteModels(cache);
|
||||
};
|
||||
|
||||
@@ -130,13 +165,35 @@ export const getStrategy = (modelConfig: ModelConfig | undefined = undefined) =>
|
||||
let params: ModelParameters;
|
||||
if (modelConfig) params = modelConfig.modelParameters;
|
||||
else params = commonStore.getCurrentModelConfig().modelParameters;
|
||||
const modelName = params.modelName.toLowerCase();
|
||||
const avoidOverflow = params.precision !== 'fp32' && modelName.includes('world') && (modelName.includes('0.1b') || modelName.includes('0.4b') ||
|
||||
modelName.includes('1.5b') || modelName.includes('1b5'));
|
||||
let strategy = '';
|
||||
strategy += (params.device === 'CPU' ? 'cpu' : 'cuda') + ' ';
|
||||
strategy += params.device === 'CPU' ? 'fp32' : (params.precision === 'fp16' ? 'fp16' : params.precision === 'int8' ? 'fp16i8' : 'fp32');
|
||||
if (params.storedLayers < params.maxStoredLayers)
|
||||
strategy += ` *${params.storedLayers}+`;
|
||||
if (params.enableHighPrecisionForLastLayer)
|
||||
strategy += ' -> cpu fp32 *1';
|
||||
switch (params.device) {
|
||||
case 'CPU':
|
||||
if (avoidOverflow)
|
||||
strategy = 'cpu fp32 *1 -> ';
|
||||
strategy += 'cpu ';
|
||||
strategy += params.precision === 'int8' ? 'fp32i8' : 'fp32';
|
||||
break;
|
||||
case 'CUDA':
|
||||
if (avoidOverflow)
|
||||
strategy = 'cuda fp32 *1 -> ';
|
||||
strategy += 'cuda ';
|
||||
strategy += params.precision === 'fp16' ? 'fp16' : params.precision === 'int8' ? 'fp16i8' : 'fp32';
|
||||
if (params.storedLayers < params.maxStoredLayers)
|
||||
strategy += ` *${params.storedLayers}+`;
|
||||
break;
|
||||
case 'MPS':
|
||||
if (avoidOverflow)
|
||||
strategy = 'mps fp32 *1 -> ';
|
||||
strategy += 'mps ';
|
||||
strategy += params.precision === 'fp16' ? 'fp16' : params.precision === 'int8' ? 'fp16i8' : 'fp32';
|
||||
break;
|
||||
case 'Custom':
|
||||
strategy = params.customStrategy || '';
|
||||
break;
|
||||
}
|
||||
return strategy;
|
||||
};
|
||||
|
||||
@@ -145,21 +202,26 @@ export const saveConfigs = async () => {
|
||||
modelSourceManifestList: commonStore.modelSourceManifestList,
|
||||
currentModelConfigIndex: commonStore.currentModelConfigIndex,
|
||||
modelConfigs: commonStore.modelConfigs,
|
||||
settings: commonStore.settings
|
||||
settings: commonStore.settings,
|
||||
dataProcessParams: commonStore.dataProcessParams,
|
||||
loraFinetuneParams: commonStore.loraFinetuneParams
|
||||
};
|
||||
return SaveJson('config.json', data);
|
||||
};
|
||||
|
||||
export const saveCache = async () => {
|
||||
const data: Cache = {
|
||||
version: manifest.version,
|
||||
models: commonStore.modelSourceList,
|
||||
introduction: commonStore.introduction,
|
||||
about: commonStore.about,
|
||||
depComplete: commonStore.depComplete
|
||||
};
|
||||
return SaveJson('cache.json', data);
|
||||
};
|
||||
|
||||
export const savePresets = async () => {
|
||||
return SaveJson('presets.json', commonStore.presets);
|
||||
};
|
||||
|
||||
export function getUserLanguage(): Language {
|
||||
// const l = navigator.language.toLowerCase();
|
||||
// if (['zh-hk', 'zh-mo', 'zh-tw', 'zh-cht', 'zh-hant'].includes(l)) return 'zhHant'
|
||||
@@ -175,16 +237,31 @@ export function isSystemLightMode() {
|
||||
|
||||
export function downloadProgramFiles() {
|
||||
manifest.programFiles.forEach(({ url, path }) => {
|
||||
FileExists(path).then(exists => {
|
||||
if (!exists)
|
||||
AddToDownloadList(path, url.replace('@master', '@v' + manifest.version));
|
||||
});
|
||||
if (path)
|
||||
ReadFileInfo(path).then(info => {
|
||||
if (info.size == 0 && url)
|
||||
AddToDownloadList(path, url.replace('@master', '@v' + manifest.version));
|
||||
}).catch(() => {
|
||||
if (url)
|
||||
AddToDownloadList(path, url.replace('@master', '@v' + manifest.version));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export function forceDownloadProgramFiles() {
|
||||
manifest.programFiles.forEach(({ url, path }) => {
|
||||
AddToDownloadList(path, url.replace('@master', '@v' + manifest.version));
|
||||
if (path && url)
|
||||
AddToDownloadList(path, url.replace('@master', '@v' + manifest.version));
|
||||
});
|
||||
}
|
||||
|
||||
export async function deleteDynamicProgramFiles() {
|
||||
let promises: Promise<void>[] = [];
|
||||
manifest.programFiles.forEach(({ path }) => {
|
||||
if ((path.endsWith('.py') && !path.includes('get-pip.py')) || path.includes('requirements') || path.endsWith('.pyd'))
|
||||
promises.push(DeleteFile(path));
|
||||
});
|
||||
return await Promise.allSettled(promises).catch(() => {
|
||||
});
|
||||
}
|
||||
|
||||
@@ -201,8 +278,7 @@ export function bytesToKb(size: number) {
|
||||
}
|
||||
|
||||
export async function checkUpdate(notifyEvenLatest: boolean = false) {
|
||||
let updateUrl = '';
|
||||
await fetch(!commonStore.settings.giteeUpdatesSource ?
|
||||
fetch(!commonStore.settings.giteeUpdatesSource ?
|
||||
'https://api.github.com/repos/josstorer/RWKV-Runner/releases/latest' :
|
||||
'https://gitee.com/api/v5/repos/josc146/RWKV-Runner/releases/latest'
|
||||
).then((r) => {
|
||||
@@ -211,28 +287,52 @@ export async function checkUpdate(notifyEvenLatest: boolean = false) {
|
||||
if (data.tag_name) {
|
||||
const versionTag = data.tag_name;
|
||||
if (versionTag.replace('v', '') > manifest.version) {
|
||||
updateUrl = !commonStore.settings.giteeUpdatesSource ?
|
||||
`https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe` :
|
||||
`https://gitee.com/josc146/RWKV-Runner/releases/download/${versionTag}/RWKV-Runner_windows_x64.exe`;
|
||||
toastWithButton(t('New Version Available') + ': ' + versionTag, t('Update'), () => {
|
||||
DeleteFile('cache.json');
|
||||
toast(t('Downloading update, please wait. If it is not completed, please manually download the program from GitHub and replace the original program.'), {
|
||||
type: 'info',
|
||||
position: 'bottom-left',
|
||||
autoClose: 10000
|
||||
});
|
||||
setTimeout(() => {
|
||||
UpdateApp(updateUrl).catch((e) => {
|
||||
toast(t('Update Error') + ' - ' + e.message || e, {
|
||||
type: 'error',
|
||||
position: 'bottom-left',
|
||||
autoClose: false
|
||||
});
|
||||
const verifyUrl = !commonStore.settings.giteeUpdatesSource ?
|
||||
`https://api.github.com/repos/josstorer/RWKV-Runner/releases/tags/${versionTag}` :
|
||||
`https://gitee.com/api/v5/repos/josc146/RWKV-Runner/releases/tags/${versionTag}`;
|
||||
|
||||
fetch(verifyUrl).then((r) => {
|
||||
if (r.ok) {
|
||||
r.json().then((data) => {
|
||||
if (data.assets && data.assets.length > 0) {
|
||||
const asset = data.assets.find((a: any) => a.name.toLowerCase().includes(commonStore.platform.toLowerCase()));
|
||||
if (asset) {
|
||||
const updateUrl = !commonStore.settings.giteeUpdatesSource ?
|
||||
`https://github.com/josStorer/RWKV-Runner/releases/download/${versionTag}/${asset.name}` :
|
||||
`https://gitee.com/josc146/RWKV-Runner/releases/download/${versionTag}/${asset.name}`;
|
||||
toastWithButton(t('New Version Available') + ': ' + versionTag, t('Update'), () => {
|
||||
DeleteFile('cache.json');
|
||||
toast(t('Downloading update, please wait. If it is not completed, please manually download the program from GitHub and replace the original program.'), {
|
||||
type: 'info',
|
||||
position: 'bottom-left',
|
||||
autoClose: false
|
||||
});
|
||||
setTimeout(() => {
|
||||
UpdateApp(updateUrl).then(() => {
|
||||
toast(t('Update completed, please restart the program.'), {
|
||||
type: 'success',
|
||||
position: 'bottom-left',
|
||||
autoClose: false
|
||||
}
|
||||
);
|
||||
}).catch((e) => {
|
||||
toast(t('Update Error') + ' - ' + (e.message || e), {
|
||||
type: 'error',
|
||||
position: 'bottom-left',
|
||||
autoClose: false
|
||||
});
|
||||
});
|
||||
}, 500);
|
||||
}, {
|
||||
autoClose: false,
|
||||
position: 'bottom-left'
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}, 500);
|
||||
}, {
|
||||
autoClose: false,
|
||||
position: 'bottom-left'
|
||||
} else {
|
||||
throw new Error('Verify response was not ok.');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (notifyEvenLatest) {
|
||||
@@ -248,11 +348,60 @@ export async function checkUpdate(notifyEvenLatest: boolean = false) {
|
||||
}
|
||||
}
|
||||
).catch((e) => {
|
||||
toast(t('Updates Check Error') + ' - ' + e.message || e, { type: 'error', position: 'bottom-left' });
|
||||
toast(t('Updates Check Error') + ' - ' + (e.message || e), { type: 'error', position: 'bottom-left' });
|
||||
});
|
||||
return updateUrl;
|
||||
}
|
||||
|
||||
export const checkDependencies = async (navigate: NavigateFunction) => {
|
||||
if (!commonStore.depComplete) {
|
||||
let depErrorMsg = '';
|
||||
await DepCheck(commonStore.settings.customPythonPath).catch((e) => {
|
||||
depErrorMsg = e.message || e;
|
||||
WindowShow();
|
||||
if (depErrorMsg === 'python zip not found') {
|
||||
toastWithButton(t('Python target not found, would you like to download it?'), t('Download'), () => {
|
||||
toastWithButton(`${t('Downloading')} Python`, t('Check'), () => {
|
||||
navigate({ pathname: '/downloads' });
|
||||
}, { autoClose: 3000 });
|
||||
AddToDownloadList('python-3.10.11-embed-amd64.zip', 'https://www.python.org/ftp/python/3.10.11/python-3.10.11-embed-amd64.zip');
|
||||
});
|
||||
} else if (depErrorMsg.includes('DepCheck Error')) {
|
||||
if (depErrorMsg.includes('vc_redist') || depErrorMsg.includes('DLL load failed while importing')) {
|
||||
toastWithButton(t('Microsoft Visual C++ Redistributable is not installed, would you like to download it?'), t('Download'), () => {
|
||||
BrowserOpenURL('https://aka.ms/vs/16/release/vc_redist.x64.exe');
|
||||
});
|
||||
} else {
|
||||
toast(depErrorMsg, { type: 'info', position: 'bottom-left' });
|
||||
if (commonStore.platform != 'linux')
|
||||
toastWithButton(t('Python dependencies are incomplete, would you like to install them?'), t('Install'), () => {
|
||||
InstallPyDep(commonStore.settings.customPythonPath, commonStore.settings.cnMirror).catch((e) => {
|
||||
const errMsg = e.message || e;
|
||||
toast(t('Error') + ' - ' + errMsg, { type: 'error' });
|
||||
});
|
||||
setTimeout(WindowShow, 1000);
|
||||
}, {
|
||||
autoClose: 8000
|
||||
});
|
||||
else
|
||||
toastWithButton(t('On Linux system, you must manually install python dependencies.'), t('Check'), () => {
|
||||
BrowserOpenURL('https://github.com/josStorer/RWKV-Runner/blob/master/build/linux/Readme_Install.txt');
|
||||
});
|
||||
}
|
||||
} else {
|
||||
toast(depErrorMsg, { type: 'error' });
|
||||
}
|
||||
});
|
||||
if (depErrorMsg) {
|
||||
commonStore.setStatus({ status: ModelStatus.Offline });
|
||||
return false;
|
||||
}
|
||||
commonStore.setDepComplete(true);
|
||||
if (commonStore.platform === 'windows')
|
||||
CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py');
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
export function toastWithButton(text: string, buttonText: string, onClickButton: () => void, options?: ToastOptions) {
|
||||
let triggered = false;
|
||||
const id = toast(
|
||||
@@ -274,9 +423,10 @@ export function toastWithButton(text: string, buttonText: string, onClickButton:
|
||||
}
|
||||
|
||||
export function getSupportedCustomCudaFile() {
|
||||
if ([' 10', ' 16', ' 20', ' 30'].some(v => commonStore.status.device_name.includes(v)))
|
||||
if ([' 10', ' 16', ' 20', ' 30', 'MX', 'Tesla P', 'Quadro P', 'NVIDIA P', 'TITAN X', 'TITAN RTX', 'RTX A',
|
||||
'Quadro RTX 4000', 'Quadro RTX 5000', 'Tesla T4', 'NVIDIA A10', 'NVIDIA A40'].some(v => commonStore.status.device_name.includes(v)))
|
||||
return './backend-python/wkv_cuda_utils/wkv_cuda10_30.pyd';
|
||||
else if ([' 40'].some(v => commonStore.status.device_name.includes(v)))
|
||||
else if ([' 40', 'RTX 5000 Ada', 'RTX 6000 Ada', 'RTX TITAN Ada', 'NVIDIA L40'].some(v => commonStore.status.device_name.includes(v)))
|
||||
return './backend-python/wkv_cuda_utils/wkv_cuda40.pyd';
|
||||
else
|
||||
return '';
|
||||
|
||||
32
frontend/wailsjs/go/backend_golang/App.d.ts
generated
vendored
Normal file → Executable file
@@ -6,13 +6,15 @@ export function AddToDownloadList(arg1:string,arg2:string):Promise<void>;
|
||||
|
||||
export function ContinueDownload(arg1:string):Promise<void>;
|
||||
|
||||
export function ConvertModel(arg1:string,arg2:string,arg3:string):Promise<string>;
|
||||
export function ConvertData(arg1:string,arg2:string,arg3:string,arg4:string):Promise<string>;
|
||||
|
||||
export function ConvertModel(arg1:string,arg2:string,arg3:string,arg4:string):Promise<string>;
|
||||
|
||||
export function CopyFile(arg1:string,arg2:string):Promise<void>;
|
||||
|
||||
export function DeleteFile(arg1:string):Promise<void>;
|
||||
|
||||
export function DepCheck():Promise<void>;
|
||||
export function DepCheck(arg1:string):Promise<void>;
|
||||
|
||||
export function DownloadFile(arg1:string,arg2:string):Promise<void>;
|
||||
|
||||
@@ -20,11 +22,17 @@ export function FileExists(arg1:string):Promise<boolean>;
|
||||
|
||||
export function GetPlatform():Promise<string>;
|
||||
|
||||
export function InstallPyDep(arg1:boolean):Promise<string>;
|
||||
export function GetPyError():Promise<string>;
|
||||
|
||||
export function InstallPyDep(arg1:string,arg2:boolean):Promise<string>;
|
||||
|
||||
export function ListDirFiles(arg1:string):Promise<Array<backend_golang.FileInfo>>;
|
||||
|
||||
export function OpenFileFolder(arg1:string):Promise<void>;
|
||||
export function MergeLora(arg1:string,arg2:boolean,arg3:number,arg4:string,arg5:string,arg6:string):Promise<string>;
|
||||
|
||||
export function OpenFileFolder(arg1:string,arg2:boolean):Promise<void>;
|
||||
|
||||
export function OpenSaveFileDialog(arg1:string,arg2:string,arg3:string):Promise<string>;
|
||||
|
||||
export function PauseDownload(arg1:string):Promise<void>;
|
||||
|
||||
@@ -32,8 +40,22 @@ export function ReadFileInfo(arg1:string):Promise<backend_golang.FileInfo>;
|
||||
|
||||
export function ReadJson(arg1:string):Promise<any>;
|
||||
|
||||
export function RestartApp():Promise<void>;
|
||||
|
||||
export function SaveJson(arg1:string,arg2:any):Promise<void>;
|
||||
|
||||
export function StartServer(arg1:number,arg2:string):Promise<string>;
|
||||
export function StartServer(arg1:string,arg2:number,arg3:string):Promise<string>;
|
||||
|
||||
export function UpdateApp(arg1:string):Promise<boolean>;
|
||||
|
||||
export function WslCommand(arg1:string):Promise<void>;
|
||||
|
||||
export function WslEnable(arg1:boolean):Promise<void>;
|
||||
|
||||
export function WslInstallUbuntu():Promise<void>;
|
||||
|
||||
export function WslIsEnabled():Promise<void>;
|
||||
|
||||
export function WslStart():Promise<void>;
|
||||
|
||||
export function WslStop():Promise<void>;
|
||||
|
||||
64
frontend/wailsjs/go/backend_golang/App.js
generated
Normal file → Executable file
@@ -10,8 +10,12 @@ export function ContinueDownload(arg1) {
|
||||
return window['go']['backend_golang']['App']['ContinueDownload'](arg1);
|
||||
}
|
||||
|
||||
export function ConvertModel(arg1, arg2, arg3) {
|
||||
return window['go']['backend_golang']['App']['ConvertModel'](arg1, arg2, arg3);
|
||||
export function ConvertData(arg1, arg2, arg3, arg4) {
|
||||
return window['go']['backend_golang']['App']['ConvertData'](arg1, arg2, arg3, arg4);
|
||||
}
|
||||
|
||||
export function ConvertModel(arg1, arg2, arg3, arg4) {
|
||||
return window['go']['backend_golang']['App']['ConvertModel'](arg1, arg2, arg3, arg4);
|
||||
}
|
||||
|
||||
export function CopyFile(arg1, arg2) {
|
||||
@@ -22,8 +26,8 @@ export function DeleteFile(arg1) {
|
||||
return window['go']['backend_golang']['App']['DeleteFile'](arg1);
|
||||
}
|
||||
|
||||
export function DepCheck() {
|
||||
return window['go']['backend_golang']['App']['DepCheck']();
|
||||
export function DepCheck(arg1) {
|
||||
return window['go']['backend_golang']['App']['DepCheck'](arg1);
|
||||
}
|
||||
|
||||
export function DownloadFile(arg1, arg2) {
|
||||
@@ -38,16 +42,28 @@ export function GetPlatform() {
|
||||
return window['go']['backend_golang']['App']['GetPlatform']();
|
||||
}
|
||||
|
||||
export function InstallPyDep(arg1) {
|
||||
return window['go']['backend_golang']['App']['InstallPyDep'](arg1);
|
||||
export function GetPyError() {
|
||||
return window['go']['backend_golang']['App']['GetPyError']();
|
||||
}
|
||||
|
||||
export function InstallPyDep(arg1, arg2) {
|
||||
return window['go']['backend_golang']['App']['InstallPyDep'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function ListDirFiles(arg1) {
|
||||
return window['go']['backend_golang']['App']['ListDirFiles'](arg1);
|
||||
}
|
||||
|
||||
export function OpenFileFolder(arg1) {
|
||||
return window['go']['backend_golang']['App']['OpenFileFolder'](arg1);
|
||||
export function MergeLora(arg1, arg2, arg3, arg4, arg5, arg6) {
|
||||
return window['go']['backend_golang']['App']['MergeLora'](arg1, arg2, arg3, arg4, arg5, arg6);
|
||||
}
|
||||
|
||||
export function OpenFileFolder(arg1, arg2) {
|
||||
return window['go']['backend_golang']['App']['OpenFileFolder'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function OpenSaveFileDialog(arg1, arg2, arg3) {
|
||||
return window['go']['backend_golang']['App']['OpenSaveFileDialog'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
export function PauseDownload(arg1) {
|
||||
@@ -62,14 +78,42 @@ export function ReadJson(arg1) {
|
||||
return window['go']['backend_golang']['App']['ReadJson'](arg1);
|
||||
}
|
||||
|
||||
export function RestartApp() {
|
||||
return window['go']['backend_golang']['App']['RestartApp']();
|
||||
}
|
||||
|
||||
export function SaveJson(arg1, arg2) {
|
||||
return window['go']['backend_golang']['App']['SaveJson'](arg1, arg2);
|
||||
}
|
||||
|
||||
export function StartServer(arg1, arg2) {
|
||||
return window['go']['backend_golang']['App']['StartServer'](arg1, arg2);
|
||||
export function StartServer(arg1, arg2, arg3) {
|
||||
return window['go']['backend_golang']['App']['StartServer'](arg1, arg2, arg3);
|
||||
}
|
||||
|
||||
export function UpdateApp(arg1) {
|
||||
return window['go']['backend_golang']['App']['UpdateApp'](arg1);
|
||||
}
|
||||
|
||||
export function WslCommand(arg1) {
|
||||
return window['go']['backend_golang']['App']['WslCommand'](arg1);
|
||||
}
|
||||
|
||||
export function WslEnable(arg1) {
|
||||
return window['go']['backend_golang']['App']['WslEnable'](arg1);
|
||||
}
|
||||
|
||||
export function WslInstallUbuntu() {
|
||||
return window['go']['backend_golang']['App']['WslInstallUbuntu']();
|
||||
}
|
||||
|
||||
export function WslIsEnabled() {
|
||||
return window['go']['backend_golang']['App']['WslIsEnabled']();
|
||||
}
|
||||
|
||||
export function WslStart() {
|
||||
return window['go']['backend_golang']['App']['WslStart']();
|
||||
}
|
||||
|
||||
export function WslStop() {
|
||||
return window['go']['backend_golang']['App']['WslStop']();
|
||||
}
|
||||
|
||||