text-generation-webui/modules/RWKV.py

28 lines
870 B
Python
Raw Normal View History

2023-02-28 04:09:11 +01:00
import os
import time
import types
2023-02-28 03:50:16 +01:00
from pathlib import Path
2023-02-28 04:09:11 +01:00
2023-02-28 03:50:16 +01:00
import numpy as np
2023-02-28 04:09:11 +01:00
import torch
import modules.shared as shared
2023-02-28 03:50:16 +01:00
np.set_printoptions(precision=4, suppress=True, linewidth=200)
os.environ['RWKV_JIT_ON'] = '1'
os.environ["RWKV_CUDA_ON"] = '0' # '1' : use CUDA kernel for seq mode (much faster)
import repositories.ChatRWKV.v2.rwkv as rwkv
from rwkv.model import RWKV
from rwkv.utils import PIPELINE, PIPELINE_ARGS
2023-02-28 04:09:11 +01:00
def load_RWKV_model(path):
print(f'strategy={"cpu" if shared.args.cpu else "cuda"} {"fp32" if shared.args.cpu else "bf16" if shared.args.bf16 else "fp16"}')
2023-02-28 03:50:16 +01:00
2023-02-28 04:09:11 +01:00
model = RWKV(model=path.as_posix(), strategy=f'{"cpu" if shared.args.cpu else "cuda"} {"fp32" if shared.args.cpu else "bf16" if shared.args.bf16 else "fp16"}')
2023-02-28 03:50:16 +01:00
pipeline = PIPELINE(model, Path("repositories/ChatRWKV/20B_tokenizer.json").as_posix())
return pipeline