Skip to content

Commit

Permalink
Mention dynamic imports, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski committed Oct 7, 2023
1 parent 486d92a commit 4eb4bdd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
[![Github Actions Status](https://github.com/krassowski/jupyterlab-transformers-completer/workflows/Build/badge.svg)](https://github.com/krassowski/jupyterlab-transformers-completer/actions/workflows/build.yml)
[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/krassowski/jupyterlab-transformers-completer/main?urlpath=lab)

Inline completion provider using `tranformers.js` for JupyterLab
Inline completion provider using `transformers.js` for JupyterLab

This extension is currently aimed for developers of JupyterLab extensions (and advanced JupyterLab users) to explore the proof of concept integration of the new inline completions API slotted for JupyterLab 4.1.

All models linked from this demonstration run exclusively **in your browser**; and are :
All models linked from this demonstration run exclusively **in your browser**, and are:

- order of magnitudes smaller than the state-of-the-art models
- producing correspondingly lower accuracy of suggestions/answers
- order of magnitudes smaller than the state-of-the-art models,
- producing correspondingly lower accuracy of suggestions/answers.

These models are not vetted for accuracy nor propriety and should not be deployed without further validation.

Expand All @@ -21,6 +21,8 @@ These models are not vetted for accuracy nor propriety and should not be deploye
- A browser supporting:
- [`SharedArrayBuffer`](https://caniuse.com/sharedarraybuffer)
- [Web Workers](https://caniuse.com/webworkers)
- Dynamic import for workers (behind `dom.workers.modules.enabled` in Firefox)
- (optional, for faster inference) [WebGPU](https://caniuse.com/webgpu) (behind `dom.webgpu.enabled` in Firefox)
- `jupyter-server` to enable additional headers (`jupyverse` and `jupyterlite` not tested yet)

When this extension is enabled, the server will return additional headers,
Expand Down
27 changes: 15 additions & 12 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,8 @@ class TransformersInlineProvider implements IInlineCompletionProvider {
});
});
}
private _workerStarted = new PromiseDelegate();
private _formatModelOptions(model: IModelInfo) {
const modelName = model.repo.replace('Xenova/', '');
return {
const: model.repo,
title: `${modelName} (${model.licence})`
};
}

get schema(): ISettingRegistry.IProperty {
// full list of models: https://huggingface.co/models?pipeline_tag=text-generation&library=transformers.js
return {
properties: {
codeModel: {
Expand Down Expand Up @@ -346,6 +337,17 @@ class TransformersInlineProvider implements IInlineCompletionProvider {
console.error(data);
}

/**
* Summarise model for display in user settings.
*/
private _formatModelOptions(model: IModelInfo) {
const modelName = model.repo.replace('Xenova/', '');
return {
const: model.repo,
title: `${modelName} (${model.licence})`
};
}

/**
* Send a tick to the worker with number of current generation counter.
*/
Expand Down Expand Up @@ -403,17 +405,18 @@ class TransformersInlineProvider implements IInlineCompletionProvider {
this._currentModels[type] = newModel;
}

private _currentGeneration = 0;
private _currentModels: {
code?: string;
text?: string;
} = {};
private _loadingNotifications: Record<string, string> = {};
private _ready: Record<string, PromiseDelegate<void>> = {};
private _settings: ISettings = DEFAULT_SETTINGS;
private _sharedArray: Int32Array;
private _streamPromises: Map<string, PromiseDelegate<IStream>> = new Map();
private _ready: Record<string, PromiseDelegate<void>> = {};
private _tokenCounter = 0;
private _sharedArray: Int32Array;
private _currentGeneration = 0;
private _workerStarted = new PromiseDelegate();
}

namespace TransformersInlineProvider {
Expand Down
4 changes: 4 additions & 0 deletions src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ export interface IModelInfo {
humanEval?: number;
}

/**
* To update the list of models, compare with:
* https://huggingface.co/models?pipeline_tag=text-generation&library=transformers.js
*/
export const codeModels: IModelInfo[] = [
{
repo: 'Xenova/tiny_starcoder_py',
Expand Down

0 comments on commit 4eb4bdd

Please sign in to comment.