TypeScript SDK Fine-tuning
How to create a fine-tuned LoRA using OctoAI's TypeScript SDK
This guide will walk you through creating a fine-tuned LoRA using our TypeScript SDK to upload image file assets, creating a tune, and then using that LoRA to run an inference using our Image Gen service once it’s ready.
Please see Fine-tuning Stable Diffusion for more specifics about each parameter in the fine-tuning API, using curl, or the Python SDK. Our Asset Library API reference documentation goes more into the specifics of using different asset methods as well.
Requirements
- Please create an OctoAI API token if you don’t have one already.
- Please also verify you’ve completed TypeScript SDK Installation & Setup.
- If you use the
OCTOAI_TOKEN
environment variable for your token, you can instantiate the client withconst octoai = new OctoAIClient()
or pass the token as a parameter to the constructor likeconst octoai = new OctoAIClient({ apiKey: process.env.OCTOAI_TOKEN })
. - An account and API token is required for all the following steps.
High-level steps to creating a fine-tuned LoRA
In order to run a LoRA fine-tuning job, you need to complete a few steps:
- Create image file assets using the Asset Library, then wait for those assets’ status to be
ready
- Either create a checkpoint asset you would like to use or get one from OctoAI’s public checkpoints.
- Create a tune job, then wait for the status to be
succeeded
. - Run an inference with the new LoRA.
Directions with all the code put together are included at the bottom of the document, but at each step we will cover additional information.
1) Creating image file assets
Asset Library in the TypeScript SDK covers more specifics about the methods, so this example will be focused on a code snippet for uploading multiple files from a folder at once.
In this example, we will use multiple photos of a toy poodle named Mitchi.
After this completes, all assets will hopefully be in the ready state, or you should time out. Mitchi is now on OctoAI!
2) Get a checkpoint asset to use for tuning our LoRA
Next, you’ll need a checkpoint to use to tune your asset. In this example, we will just use the default checkpoint using Stable Diffusion 1.5, but you can also use other public OctoAI checkpoints or create your own using the Asset Library.
3) Creating a tune
We can create a tune by passing in the id of the checkpoint we’d like to use and the ids of the file assets that we created in Step 1. If you want more accurate results, you can add captions to each image to give more thorough descriptions. If no custom captions are provided, the trigger word will be used as a default.
4) Run an inference with the tuned LoRA
Next, you can run an inference with the tuned LoRA
The end result will be a saved poodle to your local folder.
result0.jpg