Skip to content

Commit

Permalink
custom python path
Browse files Browse the repository at this point in the history
  • Loading branch information
josStorer committed May 31, 2023
1 parent b49968c commit 796e5f2
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 26 deletions.
28 changes: 20 additions & 8 deletions backend-golang/rwkv.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,33 @@ import (
"strconv"
)

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) DepCheck(python string) error {
var err error
if python == "" {
python, err = GetPython()
}
if err != nil {
return err
}
Expand All @@ -35,8 +44,11 @@ func (a *App) DepCheck() error {
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 err != nil {
return "", err
}
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/components/RunButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean

if (!commonStore.depComplete) {
let depErrorMsg = '';
await DepCheck().catch((e) => {
await DepCheck(commonStore.settings.customPythonPath).catch((e) => {
depErrorMsg = e.message || e;
WindowShow();
if (depErrorMsg === 'python zip not found') {
Expand All @@ -71,7 +71,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
});
} else if (depErrorMsg.includes('DepCheck Error')) {
toastWithButton(t('Python dependencies are incomplete, would you like to install them?'), t('Install'), () => {
InstallPyDep(commonStore.settings.cnMirror);
InstallPyDep(commonStore.settings.customPythonPath, commonStore.settings.cnMirror);
setTimeout(WindowShow, 1000);
});
} else {
Expand All @@ -83,7 +83,8 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
return;
}
commonStore.setDepComplete(true);
CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py');
if (commonStore.platform === 'windows')
CopyFile('./backend-python/wkv_cuda_utils/wkv_cuda_model.py', './py310/Lib/site-packages/rwkv/model.py');
saveCache();
}

Expand All @@ -109,7 +110,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean

await exit(1000).catch(() => {
});
StartServer(port, commonStore.settings.host !== '127.0.0.1' ? '0.0.0.0' : '127.0.0.1');
StartServer(commonStore.settings.customPythonPath, port, commonStore.settings.host !== '127.0.0.1' ? '0.0.0.0' : '127.0.0.1');
setTimeout(WindowShow, 1000);

let timeoutCount = 6;
Expand Down Expand Up @@ -137,7 +138,7 @@ export const RunButton: FC<{ onClickRun?: MouseEventHandler, iconMode?: boolean
let customCudaFile = '';
if (modelConfig.modelParameters.device != 'CPU' && modelConfig.modelParameters.useCustomCuda) {
customCudaFile = getSupportedCustomCudaFile();
if (customCudaFile) {
if (customCudaFile && commonStore.platform === 'windows') {
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');
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/Configs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ export const Configs: FC = observer(() => {
const strategy = getStrategy(selectedConfig);
const newModelPath = modelPath + '-' + strategy.replace(/[:> *+]/g, '-');
toast(t('Start Converting'), { autoClose: 1000, type: 'info' });
ConvertModel(modelPath, strategy, newModelPath).then(() => {
ConvertModel(commonStore.settings.customPythonPath, modelPath, strategy, newModelPath).then(() => {
toast(`${t('Convert Success')} - ${newModelPath}`, { type: 'success' });
refreshLocalModels({ models: commonStore.modelSourceList }, false);
}).catch(e => {
Expand Down
8 changes: 4 additions & 4 deletions frontend/wailsjs/go/backend_golang/App.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions frontend/wailsjs/go/backend_golang/App.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 796e5f2

Please sign in to comment.