-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Nitro-Tensorrt-LLM Extension (janhq#2280)
* feat: tensorrt-llm-extension * fix: loading * feat: add download tensorrt llm runner Signed-off-by: James <[email protected]> * feat: update to rollupjs instead of webpack for monitoring extension Signed-off-by: James <[email protected]> * feat: move update nvidia info to monitor extension Signed-off-by: James <[email protected]> * allow download tensorrt Signed-off-by: James <[email protected]> * update Signed-off-by: James <[email protected]> * allow download tensor rt based on gpu setting Signed-off-by: James <[email protected]> * update downloaded models Signed-off-by: James <[email protected]> * feat: add extension compatibility * dynamic tensor rt engines Signed-off-by: James <[email protected]> * update models Signed-off-by: James <[email protected]> * chore: remove ts-ignore * feat: getting installation state from extension Signed-off-by: James <[email protected]> * chore: adding type for decompress Signed-off-by: James <[email protected]> * feat: update according Louis's comment Signed-off-by: James <[email protected]> * feat: add progress for installing extension Signed-off-by: James <[email protected]> * chore: remove args from extension installation * fix: model download does not work properly * fix: do not allow user to stop tensorrtllm inference * fix: extension installed style * fix: download tensorrt does not update state Signed-off-by: James <[email protected]> * chore: replace int4 by fl16 * feat: modal for installing extension Signed-off-by: James <[email protected]> * fix: start download immediately after press install Signed-off-by: James <[email protected]> * fix: error switching between engines * feat: rename inference provider to ai engine and refactor to core * fix: missing ulid * fix: core bundler * feat: add cancel extension installing Signed-off-by: James <[email protected]> * remove mocking for mac Signed-off-by: James <[email protected]> * fix: show models only when extension is ready * add tensorrt badge for model Signed-off-by: James <[email protected]> * fix: copy * fix: add compatible check (janhq#2342) * fix: add compatible check Signed-off-by: James <[email protected]> * fix: copy * fix: font * fix: copy * fix: broken monitoring extension * chore: bump engine * fix: copy * fix: model copy * fix: copy * fix: model json --------- Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]> Co-authored-by: Louis <[email protected]> * fix: vulkan support * fix: installation button padding * fix: empty script * fix: remove hard code string --------- Signed-off-by: James <[email protected]> Co-authored-by: James <[email protected]> Co-authored-by: NamH <[email protected]>
- Loading branch information
1 parent
24c6dd0
commit d85d026
Showing
71 changed files
with
2,496 additions
and
625 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { getJanDataFolderPath, joinPath } from '../../core' | ||
import { events } from '../../events' | ||
import { BaseExtension } from '../../extension' | ||
import { fs } from '../../fs' | ||
import { Model, ModelEvent } from '../../types' | ||
|
||
/** | ||
* Base AIEngine | ||
* Applicable to all AI Engines | ||
*/ | ||
export abstract class AIEngine extends BaseExtension { | ||
// The inference engine | ||
abstract provider: string | ||
// The model folder | ||
modelFolder: string = 'models' | ||
|
||
abstract models(): Promise<Model[]> | ||
|
||
/** | ||
* On extension load, subscribe to events. | ||
*/ | ||
onLoad() { | ||
this.prePopulateModels() | ||
} | ||
|
||
/** | ||
* Pre-populate models to App Data Folder | ||
*/ | ||
prePopulateModels(): Promise<void> { | ||
return this.models().then((models) => { | ||
const prePoluateOperations = models.map((model) => | ||
getJanDataFolderPath() | ||
.then((janDataFolder) => | ||
// Attempt to create the model folder | ||
joinPath([janDataFolder, this.modelFolder, model.id]).then((path) => | ||
fs | ||
.mkdirSync(path) | ||
.catch() | ||
.then(() => path) | ||
) | ||
) | ||
.then((path) => joinPath([path, 'model.json'])) | ||
.then((path) => { | ||
// Do not overwite existing model.json | ||
return fs.existsSync(path).then((exist: any) => { | ||
if (!exist) return fs.writeFileSync(path, JSON.stringify(model, null, 2)) | ||
}) | ||
}) | ||
.catch((e: Error) => { | ||
console.error('Error', e) | ||
}) | ||
) | ||
Promise.all(prePoluateOperations).then(() => | ||
// Emit event to update models | ||
// So the UI can update the models list | ||
events.emit(ModelEvent.OnModelsUpdate, {}) | ||
) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { executeOnMain, getJanDataFolderPath, joinPath } from '../../core' | ||
import { events } from '../../events' | ||
import { Model, ModelEvent } from '../../types' | ||
import { OAIEngine } from './OAIEngine' | ||
|
||
/** | ||
* Base OAI Local Inference Provider | ||
* Added the implementation of loading and unloading model (applicable to local inference providers) | ||
*/ | ||
export abstract class LocalOAIEngine extends OAIEngine { | ||
// The inference engine | ||
loadModelFunctionName: string = 'loadModel' | ||
unloadModelFunctionName: string = 'unloadModel' | ||
isRunning: boolean = false | ||
|
||
/** | ||
* On extension load, subscribe to events. | ||
*/ | ||
onLoad() { | ||
super.onLoad() | ||
// These events are applicable to local inference providers | ||
events.on(ModelEvent.OnModelInit, (model: Model) => this.onModelInit(model)) | ||
events.on(ModelEvent.OnModelStop, (model: Model) => this.onModelStop(model)) | ||
} | ||
|
||
/** | ||
* Load the model. | ||
*/ | ||
async onModelInit(model: Model) { | ||
if (model.engine.toString() !== this.provider) return | ||
|
||
const modelFolder = await joinPath([await getJanDataFolderPath(), this.modelFolder, model.id]) | ||
|
||
const res = await executeOnMain(this.nodeModule, this.loadModelFunctionName, { | ||
modelFolder, | ||
model, | ||
}) | ||
|
||
if (res?.error) { | ||
events.emit(ModelEvent.OnModelFail, { | ||
...model, | ||
error: res.error, | ||
}) | ||
return | ||
} else { | ||
this.loadedModel = model | ||
events.emit(ModelEvent.OnModelReady, model) | ||
this.isRunning = true | ||
} | ||
} | ||
/** | ||
* Stops the model. | ||
*/ | ||
onModelStop(model: Model) { | ||
if (model.engine?.toString() !== this.provider) return | ||
|
||
this.isRunning = false | ||
|
||
executeOnMain(this.nodeModule, this.unloadModelFunctionName).then(() => { | ||
events.emit(ModelEvent.OnModelStopped, {}) | ||
}) | ||
} | ||
} |
Oops, something went wrong.