Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
549f32a743 | ||
|
|
e3b3452a73 | ||
|
|
62350d975d | ||
|
|
8d84b326b8 | ||
|
|
16079a3cba | ||
|
|
ff330a5487 |
@@ -1,10 +1,8 @@
|
||||
## Changes
|
||||
|
||||
- rwkv5 lora finetune support (https://github.com/JL-er/RWKV-v5-lora)
|
||||
- improve memory usage and speed of convert_safetensors.py
|
||||
- webgpu(python) state cache support
|
||||
- improve state cache performance (especially for rwkv.cpp)
|
||||
- chore
|
||||
- abc music inference support
|
||||
- basic abc frontend support
|
||||
- fix finetune errorsMap ($modelInfo)
|
||||
|
||||
## Install
|
||||
|
||||
|
||||
21
backend-python/rwkv_pip/utils.py
vendored
21
backend-python/rwkv_pip/utils.py
vendored
@@ -34,6 +34,25 @@ class PIPELINE_ARGS:
|
||||
)
|
||||
|
||||
|
||||
class ABC_TOKENIZER:
|
||||
def __init__(self):
|
||||
self.pad_token_id = 0
|
||||
self.bos_token_id = 2
|
||||
self.eos_token_id = 3
|
||||
|
||||
def encode(self, text):
|
||||
ids = [ord(c) for c in text]
|
||||
return ids
|
||||
|
||||
def decode(self, ids):
|
||||
txt = "".join(
|
||||
chr(idx) if idx > self.eos_token_id else ""
|
||||
for idx in ids
|
||||
if idx != self.eos_token_id
|
||||
)
|
||||
return txt
|
||||
|
||||
|
||||
class PIPELINE:
|
||||
def __init__(self, model, WORD_NAME: str):
|
||||
self.model = model
|
||||
@@ -48,6 +67,8 @@ class PIPELINE:
|
||||
self.tokenizer = TRIE_TOKENIZER(
|
||||
os.path.dirname(os.path.abspath(__file__)) + "/rwkv_vocab_v20230424.txt"
|
||||
)
|
||||
elif WORD_NAME == "abc_tokenizer":
|
||||
self.tokenizer = ABC_TOKENIZER()
|
||||
else:
|
||||
if WORD_NAME.endswith(".txt"):
|
||||
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
@@ -11,11 +11,6 @@ from pydantic import BaseModel, Field
|
||||
from routes import state_cache
|
||||
import global_var
|
||||
|
||||
|
||||
END_OF_TEXT = 0
|
||||
END_OF_LINE_DOUBLE = 535
|
||||
|
||||
|
||||
os.environ["TORCH_EXTENSIONS_DIR"] = f"{pathlib.Path(__file__).parent.parent.resolve()}"
|
||||
|
||||
|
||||
@@ -28,6 +23,8 @@ class RWKVType(Enum):
|
||||
|
||||
class AbstractRWKV(ABC):
|
||||
def __init__(self, model, pipeline):
|
||||
self.EOS_ID = 0
|
||||
|
||||
self.name = "rwkv"
|
||||
self.model = model
|
||||
self.pipeline = pipeline
|
||||
@@ -274,7 +271,7 @@ class AbstractRWKV(ABC):
|
||||
logits, temperature=self.temperature, top_p=self.top_p, top_k=self.top_k
|
||||
)
|
||||
|
||||
if token == END_OF_TEXT:
|
||||
if token == self.EOS_ID:
|
||||
yield response, "", prompt_token_len, completion_token_len
|
||||
break
|
||||
|
||||
@@ -401,7 +398,7 @@ class TextRWKV(AbstractRWKV):
|
||||
def fix_tokens(self, tokens) -> List[int]:
|
||||
if self.rwkv_type == RWKVType.World:
|
||||
return tokens
|
||||
if len(tokens) > 0 and tokens[-1] == END_OF_LINE_DOUBLE:
|
||||
if len(tokens) > 0 and tokens[-1] == 535:
|
||||
tokens = tokens[:-1] + [self.END_OF_LINE, self.END_OF_LINE]
|
||||
return tokens
|
||||
|
||||
@@ -459,7 +456,7 @@ The following is a coherent verbose detailed conversation between a girl named {
|
||||
pass
|
||||
|
||||
|
||||
class MusicRWKV(AbstractRWKV):
|
||||
class MusicMidiRWKV(AbstractRWKV):
|
||||
def __init__(self, model, pipeline):
|
||||
super().__init__(model, pipeline)
|
||||
|
||||
@@ -501,8 +498,45 @@ class MusicRWKV(AbstractRWKV):
|
||||
return " " + delta
|
||||
|
||||
|
||||
class MusicAbcRWKV(AbstractRWKV):
|
||||
def __init__(self, model, pipeline):
|
||||
super().__init__(model, pipeline)
|
||||
|
||||
self.EOS_ID = 3
|
||||
|
||||
self.max_tokens_per_generation = 500
|
||||
self.temperature = 1
|
||||
self.top_p = 0.8
|
||||
self.top_k = 8
|
||||
|
||||
self.rwkv_type = RWKVType.Music
|
||||
|
||||
def adjust_occurrence(self, occurrence: Dict, token: int):
|
||||
pass
|
||||
|
||||
def adjust_forward_logits(self, logits: List[float], occurrence: Dict, i: int):
|
||||
pass
|
||||
|
||||
def fix_tokens(self, tokens) -> List[int]:
|
||||
return tokens
|
||||
|
||||
def run_rnn(
|
||||
self, _tokens: List[str], newline_adj: int = 0
|
||||
) -> Tuple[List[float], int]:
|
||||
tokens = [int(x) for x in _tokens]
|
||||
token_len = len(tokens)
|
||||
self.model_tokens += tokens
|
||||
out, self.model_state = self.model.forward(tokens, self.model_state)
|
||||
return out, token_len
|
||||
|
||||
def delta_postprocess(self, delta: str) -> str:
|
||||
return delta
|
||||
|
||||
|
||||
def get_tokenizer(tokenizer_len: int):
|
||||
tokenizer_dir = f"{pathlib.Path(__file__).parent.parent.resolve()}/rwkv_pip/"
|
||||
if tokenizer_len < 20096:
|
||||
return "abc_tokenizer"
|
||||
if tokenizer_len < 50277:
|
||||
return tokenizer_dir + "tokenizer-midi.json"
|
||||
elif tokenizer_len < 65536:
|
||||
@@ -550,7 +584,8 @@ def RWKV(model: str, strategy: str, tokenizer: Union[str, None]) -> AbstractRWKV
|
||||
rwkv_map: dict[str, Type[AbstractRWKV]] = {
|
||||
"20B_tokenizer": TextRWKV,
|
||||
"rwkv_vocab_v20230424": TextRWKV,
|
||||
"tokenizer-midi": MusicRWKV,
|
||||
"tokenizer-midi": MusicMidiRWKV,
|
||||
"abc_tokenizer": MusicAbcRWKV,
|
||||
}
|
||||
tokenizer_name = os.path.splitext(os.path.basename(tokenizer))[0]
|
||||
rwkv: AbstractRWKV
|
||||
|
||||
10
frontend/package-lock.json
generated
10
frontend/package-lock.json
generated
@@ -13,6 +13,7 @@
|
||||
"@magenta/music": "^1.23.1",
|
||||
"@microsoft/fetch-event-source": "^2.0.1",
|
||||
"@primer/octicons-react": "^19.1.0",
|
||||
"abcjs": "^6.2.3",
|
||||
"chart.js": "^4.3.0",
|
||||
"classnames": "^2.3.2",
|
||||
"file-saver": "^2.0.5",
|
||||
@@ -2690,6 +2691,15 @@
|
||||
"integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==",
|
||||
"optional": true
|
||||
},
|
||||
"node_modules/abcjs": {
|
||||
"version": "6.2.3",
|
||||
"resolved": "https://registry.npmjs.org/abcjs/-/abcjs-6.2.3.tgz",
|
||||
"integrity": "sha512-epu8C1yRkxV7Ss9hS0Bu72rairl1p2sR3hviVowjtdDJvb5GRE0SrB4TtN4HBbaoYhvxGnSZQxGULfQlW3o3RQ==",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/paulrosen"
|
||||
}
|
||||
},
|
||||
"node_modules/acorn": {
|
||||
"version": "7.4.1",
|
||||
"resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz",
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
"@magenta/music": "^1.23.1",
|
||||
"@microsoft/fetch-event-source": "^2.0.1",
|
||||
"@primer/octicons-react": "^19.1.0",
|
||||
"abcjs": "^6.2.3",
|
||||
"chart.js": "^4.3.0",
|
||||
"classnames": "^2.3.2",
|
||||
"file-saver": "^2.0.5",
|
||||
|
||||
@@ -19,6 +19,7 @@ import { useNavigate } from 'react-router';
|
||||
import { WindowShow } from '../../wailsjs/runtime';
|
||||
import { convertToGGML, convertToSt } from '../utils/convert-model';
|
||||
import { Precision } from '../types/configs';
|
||||
import { defaultCompositionABCPrompt, defaultCompositionPrompt } from '../pages/defaultConfigs';
|
||||
|
||||
const mainButtonText = {
|
||||
[ModelStatus.Offline]: 'Run',
|
||||
@@ -257,6 +258,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
commonStore.setStatus({ status: ModelStatus.Working });
|
||||
let buttonNameMap = {
|
||||
'novel': 'Completion',
|
||||
'abc': 'Composition',
|
||||
'midi': 'Composition'
|
||||
};
|
||||
let buttonName = 'Chat';
|
||||
@@ -264,6 +266,13 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
|
||||
const buttonFn = () => {
|
||||
navigate({ pathname: '/' + buttonName.toLowerCase() });
|
||||
};
|
||||
if (modelName.toLowerCase().includes('abc') && commonStore.compositionParams.prompt === defaultCompositionPrompt) {
|
||||
commonStore.setCompositionParams({
|
||||
...commonStore.compositionParams,
|
||||
prompt: defaultCompositionABCPrompt
|
||||
});
|
||||
commonStore.setCompositionSubmittedPrompt(defaultCompositionABCPrompt);
|
||||
}
|
||||
|
||||
if (modelConfig.modelParameters.device.startsWith('CUDA') &&
|
||||
modelConfig.modelParameters.storedLayers < modelConfig.modelParameters.maxStoredLayers &&
|
||||
|
||||
@@ -15,12 +15,13 @@ import { ArrowSync20Regular, Save28Regular } from '@fluentui/react-icons';
|
||||
import { PlayerElement, VisualizerElement } from 'html-midi-player';
|
||||
import * as mm from '@magenta/music/esm/core.js';
|
||||
import { NoteSequence } from '@magenta/music/esm/protobuf.js';
|
||||
import { defaultCompositionPrompt } from './defaultConfigs';
|
||||
import { defaultCompositionABCPrompt, defaultCompositionPrompt } from './defaultConfigs';
|
||||
import {
|
||||
CloseMidiPort,
|
||||
FileExists,
|
||||
OpenFileFolder,
|
||||
OpenMidiPort,
|
||||
OpenSaveFileDialog,
|
||||
OpenSaveFileDialogBytes,
|
||||
SaveFile,
|
||||
StartFile
|
||||
@@ -36,7 +37,9 @@ const CompositionPanel: FC = observer(() => {
|
||||
const { t } = useTranslation();
|
||||
const mq = useMediaQuery('(min-width: 640px)');
|
||||
const inputRef = useRef<HTMLTextAreaElement>(null);
|
||||
const port = commonStore.getCurrentModelConfig().apiParameters.apiPort;
|
||||
const modelConfig = commonStore.getCurrentModelConfig();
|
||||
const port = modelConfig.apiParameters.apiPort;
|
||||
const isABC = modelConfig.modelParameters.modelName.toLowerCase().includes('abc');
|
||||
const visualizerRef = useRef<VisualizerElement>(null);
|
||||
const playerRef = useRef<PlayerElement>(null);
|
||||
|
||||
@@ -133,6 +136,13 @@ const CompositionPanel: FC = observer(() => {
|
||||
}, [commonStore.midiPorts]);
|
||||
|
||||
const generateNs = (autoPlay: boolean) => {
|
||||
if (commonStore.getCurrentModelConfig().modelParameters.modelName.toLowerCase().includes('abc')) {
|
||||
import('abcjs').then(ABCJS => {
|
||||
ABCJS.renderAbc('abc-paper', commonStore.compositionParams.prompt, { responsive: 'resize' });
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
fetch(getServerRoot(port) + '/text-to-midi', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
@@ -370,11 +380,13 @@ const CompositionPanel: FC = observer(() => {
|
||||
<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={() => {
|
||||
commonStore.setCompositionSubmittedPrompt(defaultCompositionPrompt);
|
||||
const isABC = commonStore.getCurrentModelConfig().modelParameters.modelName.toLowerCase().includes('abc');
|
||||
const defaultPrompt = isABC ? defaultCompositionABCPrompt : defaultCompositionPrompt;
|
||||
commonStore.setCompositionSubmittedPrompt(defaultPrompt);
|
||||
setParams({
|
||||
generationStartTime: 0
|
||||
});
|
||||
setPrompt(defaultCompositionPrompt);
|
||||
setPrompt(defaultPrompt);
|
||||
}} />
|
||||
<Button className="grow" appearance="primary" onClick={() => {
|
||||
if (commonStore.compositionGenerating) {
|
||||
@@ -394,18 +406,33 @@ const CompositionPanel: FC = observer(() => {
|
||||
</div>
|
||||
<div className="flex flex-col">
|
||||
<div className="ml-auto mr-auto">
|
||||
<midi-visualizer
|
||||
ref={visualizerRef}
|
||||
type="waterfall"
|
||||
/>
|
||||
{isABC ? <div /> :
|
||||
<midi-visualizer
|
||||
ref={visualizerRef}
|
||||
type="waterfall"
|
||||
/>}
|
||||
</div>
|
||||
<div className="flex">
|
||||
<midi-player
|
||||
ref={playerRef}
|
||||
style={{ width: '100%' }}
|
||||
/>
|
||||
{isABC ? <div className="flex flex-col overflow-y-auto grow m-1" style={{ maxHeight: '260px' }}>
|
||||
<div id="abc-paper" />
|
||||
</div> :
|
||||
<midi-player
|
||||
ref={playerRef}
|
||||
style={{ width: '100%' }}
|
||||
/>}
|
||||
<Button icon={<Save28Regular />} size={mq ? 'large' : 'medium'} appearance={mq ? 'secondary' : 'subtle'}
|
||||
onClick={() => {
|
||||
if (isABC) {
|
||||
OpenSaveFileDialog('*.txt', 'abc-music.txt', commonStore.compositionParams.prompt).then((path) => {
|
||||
if (path)
|
||||
toastWithButton(t('File Saved'), t('Open'), () => {
|
||||
OpenFileFolder(path, false);
|
||||
});
|
||||
}).catch((e) => {
|
||||
toast(t('Error') + ' - ' + (e.message || e), { type: 'error', autoClose: 2500 });
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (params.midi) {
|
||||
OpenSaveFileDialogBytes('*.mid', 'music.mid', Array.from(new Uint8Array(params.midi))).then((path) => {
|
||||
if (path)
|
||||
|
||||
@@ -131,7 +131,7 @@ const showError = (e: any) => {
|
||||
};
|
||||
|
||||
const errorsMap = Object.entries({
|
||||
'python3 ./finetune/lora/v': 'Memory is not enough, try to increase the virtual memory (Swap of WSL) or use a smaller base model.',
|
||||
'python3 ./finetune/lora/$modelInfo': 'Memory is not enough, try to increase the virtual memory (Swap of WSL) 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\'': 'Can not find an Nvidia GPU. Perhaps the gpu driver of windows is too old, or you are using WSL 1 for training, please upgrade to WSL 2. e.g. Run "wsl --set-version Ubuntu-22.04 2"',
|
||||
|
||||
@@ -2,6 +2,17 @@ import { CompletionPreset } from '../types/completion';
|
||||
import { ModelConfig } from '../types/configs';
|
||||
|
||||
export const defaultCompositionPrompt = '<pad>';
|
||||
export const defaultCompositionABCPrompt='S:3\n' +
|
||||
'B:9\n' +
|
||||
'E:4\n' +
|
||||
'B:9\n' +
|
||||
'E:4\n' +
|
||||
'E:4\n' +
|
||||
'B:9\n' +
|
||||
'L:1/8\n' +
|
||||
'M:3/4\n' +
|
||||
'K:D\n' +
|
||||
' Bc |"G" d2 cB"A" A2 FE |"Bm" F2 B4 F^G |'
|
||||
|
||||
export const defaultPresets: CompletionPreset[] = [{
|
||||
name: 'Writer',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"version": "1.6.6",
|
||||
"version": "1.6.7",
|
||||
"introduction": {
|
||||
"en": "RWKV is an open-source, commercially usable large language model with high flexibility and great potential for development.\n### About This Tool\nThis tool aims to lower the barrier of entry for using large language models, making it accessible to everyone. It provides fully automated dependency and model management. You simply need to click and run, following the instructions, to deploy a local large language model. The tool itself is very compact and only requires a single executable file for one-click deployment.\nAdditionally, this tool offers an interface that is fully compatible with the OpenAI API. This means you can use any ChatGPT client as a client for RWKV, enabling capability expansion beyond just chat functionality.\n### Preset Configuration Rules at the Bottom\nThis tool comes with a series of preset configurations to reduce complexity. The naming rules for each configuration represent the following in order: device - required VRAM/memory - model size - model language.\nFor example, \"GPU-8G-3B-EN\" indicates that this configuration is for a graphics card with 8GB of VRAM, a model size of 3 billion parameters, and it uses an English language model.\nLarger model sizes have higher performance and VRAM requirements. Among configurations with the same model size, those with higher VRAM usage will have faster runtime.\nFor example, if you have 12GB of VRAM but running the \"GPU-12G-7B-EN\" configuration is slow, you can downgrade to \"GPU-8G-3B-EN\" for a significant speed improvement.\n### About RWKV\nRWKV is an RNN with Transformer-level LLM performance, which can also be directly trained like a GPT transformer (parallelizable). And it's 100% attention-free. You only need the hidden state at position t to compute the state at position t+1. You can use the \"GPT\" mode to quickly compute the hidden state for the \"RNN\" mode.<br/>So it's combining the best of RNN and transformer - great performance, fast inference, saves VRAM, fast training, \"infinite\" ctx_len, and free sentence embedding (using the final hidden state).",
|
||||
"zh": "RWKV是一个开源且允许商用的大语言模型,灵活性很高且极具发展潜力。\n### 关于本工具\n本工具旨在降低大语言模型的使用门槛,做到人人可用,本工具提供了全自动化的依赖和模型管理,你只需要直接点击运行,跟随引导,即可完成本地大语言模型的部署,工具本身体积极小,只需要一个exe即可完成一键部署。\n此外,本工具提供了与OpenAI API完全兼容的接口,这意味着你可以把任意ChatGPT客户端用作RWKV的客户端,实现能力拓展,而不局限于聊天。\n### 底部的预设配置规则\n本工具内置了一系列预设配置,以降低使用难度,每个配置名的规则,依次代表着:设备-所需显存/内存-模型规模-模型语言。\n例如,GPU-8G-3B-CN,表示该配置用于显卡,需要8G显存,模型规模为30亿参数,使用的是中文模型。\n模型规模越大,性能要求越高,显存要求也越高,而同样模型规模的配置中,显存占用越高的,运行速度越快。\n例如当你有12G显存,但运行GPU-12G-7B-CN配置速度比较慢,可降级成GPU-8G-3B-CN,将会大幅提速。\n### 关于RWKV\nRWKV是具有Transformer级别LLM性能的RNN,也可以像GPT Transformer一样直接进行训练(可并行化)。而且它是100% attention-free的。你只需在位置t处获得隐藏状态即可计算位置t + 1处的状态。你可以使用“GPT”模式快速计算用于“RNN”模式的隐藏状态。\n因此,它将RNN和Transformer的优点结合起来 - 高性能、快速推理、节省显存、快速训练、“无限”上下文长度以及免费的语句嵌入(使用最终隐藏状态)。"
|
||||
@@ -1214,6 +1214,24 @@
|
||||
"Music"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "RWKV-4-ABC-82M-v1-20230805-ctx1024.pth",
|
||||
"desc": {
|
||||
"en": "Music ABC 82M v1",
|
||||
"zh": "作曲 ABC 82M v1",
|
||||
"ja": "作曲 ABC 82M v1"
|
||||
},
|
||||
"size": 164183345,
|
||||
"SHA256": "4c83859f387bc3953d19890338a3e50ea7f2278e1bbb9d6eae9b773c81958a01",
|
||||
"lastUpdated": "2023-08-06T05:46:55",
|
||||
"url": "https://huggingface.co/BlinkDL/rwkv-4-music/blob/main/RWKV-4-ABC-82M-v1-20230805-ctx1024.pth",
|
||||
"downloadUrl": "https://huggingface.co/BlinkDL/rwkv-4-music/resolve/main/RWKV-4-ABC-82M-v1-20230805-ctx1024.pth",
|
||||
"tags": [
|
||||
"Main",
|
||||
"RWKV-4",
|
||||
"Music"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "RWKV-5-MIDI-120M-v1-20230728-ctx4096.pth",
|
||||
"desc": {
|
||||
@@ -1249,6 +1267,24 @@
|
||||
"RWKV-5",
|
||||
"Music"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "RWKV-5-ABC-82M-v1-20230901-ctx1024.pth",
|
||||
"desc": {
|
||||
"en": "RWKV-5 Music ABC 82M v1",
|
||||
"zh": "RWKV-5 作曲 ABC 82M v1",
|
||||
"ja": "RWKV-5 作曲 ABC 82M v1"
|
||||
},
|
||||
"size": 164222002,
|
||||
"SHA256": "5bf9ae32e4ef05c3851d6010709c6c00dda926d110766b9a712bc48c0a53e098",
|
||||
"lastUpdated": "2023-09-02T06:55:12",
|
||||
"url": "https://huggingface.co/BlinkDL/rwkv-5-music/blob/main/RWKV-5-ABC-82M-v1-20230901-ctx1024.pth",
|
||||
"downloadUrl": "https://huggingface.co/BlinkDL/rwkv-5-music/resolve/main/RWKV-5-ABC-82M-v1-20230901-ctx1024.pth",
|
||||
"tags": [
|
||||
"Main",
|
||||
"RWKV-5",
|
||||
"Music"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user