Skip to content
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

fix: upload model on podman machine on WSL to speed loading #204

Merged
merged 10 commits into from
Mar 13, 2024
Prev Previous commit
fix: update remote path where to store uploaded model
Signed-off-by: lstocchi <lstocchi@redhat.com>
  • Loading branch information
lstocchi committed Mar 13, 2024
commit a2ef7da1edc3ae62c384a7faf349eb488ecdcbff
33 changes: 28 additions & 5 deletions packages/backend/src/utils/WSLUploader.spec.ts
Original file line number Diff line number Diff line change
@@ -76,20 +76,43 @@ describe('upload', () => {
mocks.execMock.mockRejectedValueOnce('error');
vi.spyOn(utils, 'getFirstRunningMachineName').mockReturnValue('machine2');
await wslUploader.upload('C:\\Users\\podman\\folder\\file');
expect(mocks.execMock).toBeCalledWith('podman', ['machine', 'ssh', 'machine2', 'stat', '/home/user/file']);
expect(mocks.execMock).toBeCalledWith('podman', [
'machine',
'ssh',
'machine2',
'stat',
'/home/user/ai-studio/models/file',
]);
expect(mocks.execMock).toBeCalledWith('podman', [
'machine',
'ssh',
'machine2',
'mkdir',
'-p',
'/home/user/ai-studio/models/',
]);
expect(mocks.execMock).toBeCalledWith('podman', [
'machine',
'ssh',
'machine2',
'cp',
'/mnt/c/Users/podman/folder/file',
'/home/user/ai-studio/models/file',
]);
mocks.execMock.mockClear();
});
test('do not copy model if it exists on podman machine', async () => {
mocks.execMock.mockResolvedValue('');
vi.spyOn(utils, 'getFirstRunningMachineName').mockReturnValue('machine2');
await wslUploader.upload('C:\\Users\\podman\\folder\\file');
expect(mocks.execMock).toBeCalledWith('podman', ['machine', 'ssh', 'machine2', 'stat', '/home/user/file']);
expect(mocks.execMock).toBeCalledWith('podman', [
'machine',
'ssh',
'machine2',
'cp',
'/mnt/c/Users/podman/folder/file',
'/home/user/file',
'stat',
'/home/user/ai-studio/models/file',
]);
expect(mocks.execMock).toBeCalledTimes(1);
mocks.execMock.mockClear();
});
});
10 changes: 6 additions & 4 deletions packages/backend/src/utils/WSLUploader.ts
Original file line number Diff line number Diff line change
@@ -35,7 +35,8 @@ export class WSLUploader implements UploadWorker {
const convertToMntPath = localPath
.replace(`${driveLetter}:\\`, `/mnt/${driveLetter.toLowerCase()}/`)
.replace(/\\/g, '/');
const remotePath = `/home/user/${path.basename(convertToMntPath)}`;
const remotePath = '/home/user/ai-studio/models/';
const remoteFile = `${remotePath}${path.basename(convertToMntPath)}`;
const machineName = getFirstRunningMachineName();

if (!machineName) {
@@ -44,23 +45,24 @@ export class WSLUploader implements UploadWorker {
// check if model already loaded on the podman machine
let existsRemote = true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In another PR, that would be better to have this as a callable method, so we could allow from the model list to upload it to the podman machine manually by the user. We would also probably want to be able to delete them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, I agree 👍

try {
await podmanDesktopApi.process.exec(getPodmanCli(), ['machine', 'ssh', machineName, 'stat', remotePath]);
await podmanDesktopApi.process.exec(getPodmanCli(), ['machine', 'ssh', machineName, 'stat', remoteFile]);
} catch (e) {
existsRemote = false;
}

// if not exists remotely it copies it from the local path
if (!existsRemote) {
await podmanDesktopApi.process.exec(getPodmanCli(), ['machine', 'ssh', machineName, 'mkdir', '-p', remotePath]);
await podmanDesktopApi.process.exec(getPodmanCli(), [
'machine',
'ssh',
machineName,
'cp',
convertToMntPath,
remotePath,
remoteFile,
]);
}

return remotePath;
return remoteFile;
}
}