RWKV.py 810 B

1234567891011121314151617181920212223242526
  1. import os
  2. import time
  3. import types
  4. from pathlib import Path
  5. import numpy as np
  6. import torch
  7. import modules.shared as shared
  8. np.set_printoptions(precision=4, suppress=True, linewidth=200)
  9. os.environ['RWKV_JIT_ON'] = '1'
  10. os.environ["RWKV_CUDA_ON"] = '0' # '1' : use CUDA kernel for seq mode (much faster)
  11. from rwkv.model import RWKV
  12. from rwkv.utils import PIPELINE, PIPELINE_ARGS
  13. def load_RWKV_model(path):
  14. print(f'strategy={"cpu" if shared.args.cpu else "cuda"} {"fp32" if shared.args.cpu else "bf16" if shared.args.bf16 else "fp16"}')
  15. 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"}')
  16. pipeline = PIPELINE(model, Path("models/20B_tokenizer.json").as_posix())
  17. return pipeline