Skip to content

Enable cuda #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 70 additions & 70 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/miniconda
{
"name": "Miniconda (Python 3)",
"image": "mcr.microsoft.com/devcontainers/miniconda:0-3",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"installOhMyZsh": true,
"upgradePackages": true,
"username": "automatic",
"userUid": "automatic",
"userGid": "automatic"
},
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "18"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"enableNonRootDocker": "true",
"moby": "true"
},
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {},
},
"mounts": [
// node modules cache
"source=${localWorkspaceFolderBasename}-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume",
// models cache
{
"source": "models",
"target": "/models",
"type": "volume"
},
// pip cachce
{
"source": "${localWorkspaceFolderBasename}-pip-cache",
"target": "/home/vscode/.cache/pip",
"type": "volume"
},
],
"remoteEnv": {
"MODELS_DIR": "/models",
"MODEL_FILE": "RWKV-4-Pile-1B5-20220929-ctx4096"
},
// If you have a gpu this will pass it in!
// "runArgs": [
// "--gpus",
// "all"
// ],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
3000,
8080
],
"postCreateCommand": "npm i -g diff-so-fancy && conda init zsh && sudo chown -R vscode node_modules ~/.cache",
"postStartCommand": "npm install",
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"GitHub.copilot",
"ms-python.pylint",
"ms-python.python",
"streetsidesoftware.code-spell-checker",
],
"settings": {}
},
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
"name": "Miniconda (Python 3)",
"image": "mcr.microsoft.com/devcontainers/miniconda:0-3",
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"installOhMyZsh": true,
"upgradePackages": true,
"username": "automatic",
"userUid": "automatic",
"userGid": "automatic"
},
"ghcr.io/devcontainers/features/node:1": {
"nodeGypDependencies": true,
"version": "18"
},
"ghcr.io/devcontainers/features/docker-in-docker:2": {
"version": "latest",
"enableNonRootDocker": "true",
"moby": "true"
},
"ghcr.io/stuartleeks/dev-container-features/shell-history:0": {},
},
"mounts": [
// node modules cache
"source=${localWorkspaceFolderBasename}-node_modules,target=${containerWorkspaceFolder}/node_modules,type=volume",
// models cache
{
"source": "models",
"target": "/models",
"type": "volume"
},
// pip cachce
{
"source": "${localWorkspaceFolderBasename}-pip-cache",
"target": "/home/vscode/.cache/pip",
"type": "volume"
},
],
"remoteEnv": {
"MODELS_DIR": "/workspaces/rwkv-web-inference/models",
"MODEL_FILE": "RWKV-4-Raven-1B5-v8-Eng-20230408-ctx4096"
},
// If you have a gpu this will pass it in!
"runArgs": [
"--gpus",
"all"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
3000,
8080
],
"postCreateCommand": "npm i -g diff-so-fancy && conda init zsh && sudo chown -R vscode node_modules ~/.cache",
"postStartCommand": "npm install",
"customizations": {
"vscode": {
"extensions": [
"dbaeumer.vscode-eslint",
"GitHub.copilot",
"ms-python.pylint",
"ms-python.python",
"streetsidesoftware.code-spell-checker",
],
"settings": {}
},
},
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
# restart: always
environment:
- MODELS_DIR=/models
- MODEL_FILE=RWKV-4-Pile-1B5-20220929-ctx4096
- MODEL_FILE=RWKV-4-Raven-1B5-v8-Eng-20230408-ctx4096
volumes:
- models:/models
ports:
Expand Down
32 changes: 16 additions & 16 deletions scripts/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,25 @@ const concurrently = require('concurrently');
const path = require('node:path');

const { result } = concurrently(
[
[
{
command: 'npm run dev',
name: 'chat client',
cwd: path.resolve(__dirname, '../packages/chat-client'),
},
{
command: "/opt/conda/bin/python app.py 0 -h 0.0.0.0 -p 8080",
name: 'chat server',
cwd: path.resolve(__dirname, '../server'),
}
],
{
command: 'npm run dev',
name: 'chat client',
cwd: path.resolve(__dirname, '../packages/chat-client'),
},
{
command: "flask run -h 0.0.0.0 -p 8080",
name: 'chat server',
cwd: path.resolve(__dirname, '../server'),
prefix: 'name',
killOthers: ['failure', 'success'],
}
],
{
prefix: 'name',
killOthers: ['failure', 'success'],
}
);

result.catch((error) => {
console.error(error);
process.exit(1);
console.error(error);
process.exit(1);
})
20 changes: 16 additions & 4 deletions server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
os.environ["CUDA_VISIBLE_DEVICES"] = sys.argv[1]
except:
pass

torch.backends.cudnn.benchmark = True
torch.backends.cudnn.allow_tf32 = True
torch.backends.cuda.matmul.allow_tf32 = True
Expand All @@ -39,16 +40,23 @@
# Do this first: pip install torchdynamo
########################################################################################################

# args.RUN_DEVICE = "cuda" # 'cpu' (already very fast) // 'cuda'
# args.FLOAT_MODE = "bf16" # fp32 (good for cpu) // fp16 (might overflow) // bf16 (less accurate)
args.RUN_DEVICE = "cuda" # 'cpu' (already very fast) // 'cuda'
# fp32 (good for cpu) // fp16 (might overflow) // bf16 (less accurate)
args.FLOAT_MODE = "fp16"

args.RUN_DEVICE = "cpu" # 'cpu' (already very fast) // 'cuda'
# args.RUN_DEVICE = "cpu" # 'cpu' (already very fast) // 'cuda'
# fp32 (good for cpu) // fp16 (might overflow) // bf16 (less accurate)
args.FLOAT_MODE = "fp32"
# args.FLOAT_MODE = "fp32"

# if args.RUN_DEVICE == "cuda":
# os.environ["RWKV_RUN_BACKEND"] = 'nvfuser' # !!!BUGGY!!! wrong output

if args.RUN_DEVICE == "cuda":
print("cuda device count: ", torch.cuda.device_count())
print("current cuda device: ", torch.cuda.current_device())
print(torch.cuda.get_device_name(0))


TOKEN_MODE = "pile"
WORD_NAME = [
"20B_tokenizer.json",
Expand Down Expand Up @@ -239,3 +247,7 @@ def help_response():
response.headers['Access-Control-Allow-Headers'] = 'Origin,X-Requested-With,Content-Type,Accept,Authorization'

return response


if __name__ == '__main__':
app.run(host="0.0.0.0", port=8080)
2 changes: 1 addition & 1 deletion server/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fi
pushd "$MODELS_DIR"

if [ ! -f "${MODEL_FILE}.pth" ]; then
wget -q https://huggingface.co/BlinkDL/rwkv-4-pile-1b5/resolve/main/RWKV-4-Pile-1B5-20220929-ctx4096.pth
wget -q https://huggingface.co/BlinkDL/rwkv-4-raven/resolve/main/RWKV-4-Raven-1B5-v8-Eng-20230408-ctx4096.pth
fi

popd
Expand Down
7 changes: 5 additions & 2 deletions server/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
torch==1.13.1
torch==1.13.1+cu116
numpy==1.24.1
flask==2.2.2
transformers==4.25.1
transformers==4.25.1

# package location
--find-links https://download.pytorch.org/whl/torch_stable.html