-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[Components] lamini - new components #16822
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
103 changes: 103 additions & 0 deletions
103
components/lamini/actions/create-fine-tune-job/create-fine-tune-job.mjs
This file contains hidden or 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,103 @@ | ||
| import app from "../../lamini.app.mjs"; | ||
| import constants from "../../common/constants.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "lamini-create-fine-tune-job", | ||
| name: "Create Fine-Tune Job", | ||
| description: "Create a fine-tuning job with a dataset. [See the documentation](https://docs.lamini.ai/api/).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| modelName: { | ||
| description: "Base model to be fine-tuned.", | ||
| propDefinition: [ | ||
| app, | ||
| "modelName", | ||
| () => ({ | ||
| includeFineTunedModels: false, | ||
| }), | ||
| ], | ||
| }, | ||
| datasetId: { | ||
| type: "string", | ||
| label: "Dataset ID", | ||
| description: "Previously uploaded dataset to use for training. Please use the **Upload Dataset** action to upload a dataset.", | ||
| }, | ||
| fineTuneArgs: { | ||
| type: "object", | ||
| label: "Finetune Arguments", | ||
| description: "Optional hyperparameters for fine-tuning. Each property is optional:\n- `index_pq_m`: Number of subquantizers for PQ (eg. 8)\n- `index_max_size`: Maximum index size (eg. 65536)\n- `max_steps`: Maximum number of training steps (eg. 60)\n- `batch_size`: Training batch size (eg. 1)\n- `learning_rate`: Learning rate (eg. 0.0003)\n- `index_pq_nbits`: Number of bits per subquantizer (eg. 8)\n- `max_length`: Maximum sequence length (eg. 2048)\n- `index_ivf_nlist`: Number of IVF lists (eg. 2048)\n- `save_steps`: Steps between checkpoints (eg. 60)\n- `args_name`: Name for the argument set (eg. \"demo\")\n- `r_value`: R value for LoRA (eg. 32)\n- `index_hnsw_m`: Number of neighbors in HNSW (eg. 32)\n- `index_method`: Indexing method (eg. \"IndexIVFPQ\")\n- `optim`: Optimizer to use (eg. \"adafactor\")\n- `index_hnsw_efConstruction`: HNSW construction parameter (eg. 16)\n- `index_hnsw_efSearch`: HNSW search parameter (eg. 8)\n- `index_k`: Number of nearest neighbors (eg. 2)\n- `index_ivf_nprobe`: Number of IVF probes (eg. 48)\n- `eval_steps`: Steps between evaluations (eg. 30)\n[See the documentation](https://docs.lamini.ai/tuning/hyperparameters/#finetune_args).", | ||
| optional: true, | ||
| }, | ||
| gpuConfig: { | ||
| type: "object", | ||
| label: "GPU Config", | ||
| description: "Optional GPU configuration for fine-tuning. [See the documentation](https://docs.lamini.ai/tuning/hyperparameters/#gpu_config).", | ||
| optional: true, | ||
| }, | ||
| isPublic: { | ||
| type: "boolean", | ||
| label: "Is Public", | ||
| description: "Whether this fine-tuning job and dataset should be publicly accessible.", | ||
| optional: true, | ||
| }, | ||
| customModelName: { | ||
| type: "string", | ||
| label: "Custom Model Name", | ||
| description: "A human-readable name for the fine-tuned model.", | ||
| optional: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| createFineTuneJob(args = {}) { | ||
| return this.app.post({ | ||
| versionPath: constants.VERSION_PATH.V1, | ||
| path: "/train", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| app, | ||
| createFineTuneJob, | ||
| modelName, | ||
| datasetId, | ||
| fineTuneArgs, | ||
| gpuConfig, | ||
| isPublic, | ||
| customModelName, | ||
| } = this; | ||
|
|
||
| const { upload_base_path: uploadBasePath } = | ||
| await app.getUploadBasePath({ | ||
| $, | ||
| }); | ||
|
|
||
| await app.getExistingDataset({ | ||
| $, | ||
| data: { | ||
| dataset_id: datasetId, | ||
| upload_base_path: uploadBasePath, | ||
| }, | ||
| }); | ||
|
|
||
| const response = await createFineTuneJob({ | ||
| $, | ||
| data: { | ||
| model_name: modelName, | ||
| dataset_id: datasetId, | ||
| upload_file_path: `${uploadBasePath}/${datasetId}.jsonlines`, | ||
| finetune_args: utils.parseJson(fineTuneArgs), | ||
| gpu_config: utils.parseJson(gpuConfig), | ||
| is_public: isPublic, | ||
| custom_model_name: customModelName, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully created a fine-tune job with ID \`${response.job_id}\`.`); | ||
| return response; | ||
| }, | ||
| }; | ||
This file contains hidden or 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,43 @@ | ||
| import app from "../../lamini.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "lamini-evaluate-job", | ||
| name: "Evaluate Job", | ||
| description: "Evaluate a fine-tuning job by job ID. [See the documentation](https://docs.lamini.ai/api/).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| jobId: { | ||
| propDefinition: [ | ||
| app, | ||
| "jobId", | ||
| ], | ||
| description: "The ID of the fine-tuning job to evaluate.", | ||
| }, | ||
| }, | ||
| methods: { | ||
| evaluateJob({ | ||
| jobId, ...args | ||
| } = {}) { | ||
| return this.app.makeRequest({ | ||
| path: `/finetune_eval/jobs/${jobId}`, | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| evaluateJob, | ||
| jobId, | ||
| } = this; | ||
|
|
||
| const response = await evaluateJob({ | ||
| $, | ||
| jobId, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully evaluated job with ID \`${jobId}\`.`); | ||
| return response; | ||
| }, | ||
| }; |
75 changes: 75 additions & 0 deletions
75
components/lamini/actions/generate-completion/generate-completion.mjs
This file contains hidden or 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,75 @@ | ||
| import app from "../../lamini.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "lamini-generate-completion", | ||
| name: "Generate Completion", | ||
| description: "Generate completions using a Lamini model. [See the documentation](https://docs.lamini.ai/api/).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| modelName: { | ||
| propDefinition: [ | ||
| app, | ||
| "modelName", | ||
| ], | ||
| description: "The model to use for completion.", | ||
| }, | ||
| prompt: { | ||
| type: "string", | ||
| label: "Prompt", | ||
| description: "The prompt to send to the model.", | ||
| }, | ||
| outputType: { | ||
| propDefinition: [ | ||
| app, | ||
| "outputType", | ||
| ], | ||
| }, | ||
| maxTokens: { | ||
| propDefinition: [ | ||
| app, | ||
| "maxTokens", | ||
| ], | ||
| }, | ||
| maxNewTokens: { | ||
| propDefinition: [ | ||
| app, | ||
| "maxNewTokens", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| generateCompletion(args = {}) { | ||
| return this.app.post({ | ||
| path: "/completions", | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| generateCompletion, | ||
| modelName, | ||
| prompt, | ||
| outputType, | ||
| maxTokens, | ||
| maxNewTokens, | ||
| } = this; | ||
|
|
||
| const response = await generateCompletion({ | ||
| $, | ||
| data: { | ||
| model_name: modelName, | ||
| prompt, | ||
| output_type: utils.parseJson(outputType), | ||
| max_tokens: maxTokens, | ||
| max_new_tokens: maxNewTokens, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully generated completion for prompt with model ${modelName}.`); | ||
| return response; | ||
| }, | ||
| }; |
88 changes: 88 additions & 0 deletions
88
components/lamini/actions/get-batch-completions/get-batch-completions.mjs
This file contains hidden or 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,88 @@ | ||
| import app from "../../lamini.app.mjs"; | ||
| import utils from "../../common/utils.mjs"; | ||
|
|
||
| export default { | ||
| key: "lamini-get-batch-completions", | ||
| name: "Get Batch Completions", | ||
| description: "Retrieve the results of a batch completion request from Lamini. [See the documentation](https://docs.lamini.ai/api/).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| modelName: { | ||
| propDefinition: [ | ||
| app, | ||
| "modelName", | ||
| ], | ||
| }, | ||
| prompt: { | ||
| type: "string[]", | ||
| label: "Prompts", | ||
| description: "The prompts to use for completion.", | ||
| }, | ||
| outputType: { | ||
| propDefinition: [ | ||
| app, | ||
| "outputType", | ||
| ], | ||
| }, | ||
| maxTokens: { | ||
| propDefinition: [ | ||
| app, | ||
| "maxTokens", | ||
| ], | ||
| }, | ||
| maxNewTokens: { | ||
| propDefinition: [ | ||
| app, | ||
| "maxNewTokens", | ||
| ], | ||
| }, | ||
| }, | ||
| methods: { | ||
| submitBatchCompletions(args = {}) { | ||
| return this.app.post({ | ||
| path: "/batch_completions", | ||
| ...args, | ||
| }); | ||
| }, | ||
| getBatchCompletions({ | ||
| id, ...args | ||
| } = {}) { | ||
| return this.app.makeRequest({ | ||
| path: `/batch_completions/${id}/result`, | ||
| ...args, | ||
| }); | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| submitBatchCompletions, | ||
| getBatchCompletions, | ||
| modelName, | ||
| prompt, | ||
| outputType, | ||
| maxTokens, | ||
| maxNewTokens, | ||
| } = this; | ||
|
|
||
| const { id } = await submitBatchCompletions({ | ||
| $, | ||
| data: { | ||
| model_name: modelName, | ||
| prompt, | ||
| output_type: utils.parseJson(outputType), | ||
| max_tokens: maxTokens, | ||
| max_new_tokens: maxNewTokens, | ||
| }, | ||
| }); | ||
|
|
||
| const response = await getBatchCompletions({ | ||
| $, | ||
| id, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully submitted batch completion with ID \`${id}\`.`); | ||
| return response; | ||
jcortes marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| }; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.