Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
},
};
43 changes: 43 additions & 0 deletions components/lamini/actions/evaluate-job/evaluate-job.mjs
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;
},
};
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;
},
};
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;
},
};
Loading
Loading