Fine-tuning Guide for Tensorfuse
This guide explains how to fine-tune Llama models using Tensorfuse’s QLoRA implementation.Supported Models
Dataset Preparation
Tensorfuse accepts datasets in JSONL format, where each line contains a valid JSON object. The following example shows the format for a conversational dataset using the ChatML format:Dataset Commands
Authenticating Huggingface and W&B
Create required secrets. Tensorkube uses Kubernetes Event Driven Autoscaling (KEDA) under the hood to scale and schedule training runs. Hence, you need to create your secrets in thekeda environment:
1
Access to Llama 3.1
Llama-3.3 requires a license agreement. Visit the Llama 3.1 huggingface repo to ensure that
you have signed the agreement and have access to the model.
2
Set huggingface token
Get a Ensure that the key for your secret is
WRITE token from your huggingface profile and store it as a secret in Tensorfuse using the command below.HUGGING_FACE_HUB_TOKEN as Tensorfuse assumes the same.If you dont wish to upload your models to your huggingface account, you can use the
READ token.3
Set your W&B authentication token
Weights and Biases (W&B) is used for logging and monitoring training runs. You need to create a W&B account and get an API key. Store it as a secret in Tensorfuse using the command below.
Programatic Access
Tensorfuse allows you to interact with the TensorKube cluster using the Python SDK, which provides a straightforward interface for creating fine-tuning jobs.Authentication
First, you need to create access keys, which are required to authenticate with the TensorKube cluster deployed in your cloud.You can skip this step if you are running the training runs from local machine as your default user will have sufficient permissions.
The LoRA adapter weights stored in the S3 bucket are in
float32 format. To store the adapter weights in bfloat16 format instead, set the store_weights_as_bf16 flag to True.get_job_status function. The function returns the status of the job as QUEUED, PROCESSING, COMPLETED, or FAILED.
- find the s3 bucket with prefix
tensorkube-keda-train-bucket. All your training lora adapters will reside here. We construct adapter id from yourjob-idand the type of gpus used for training so your adapter urls would look like this:-s3://<bucket-name>/lora-adapter/<job_name>/<job_id>
fine-tuning-job and job-id unique_id, trained on 4 gpu of type l40s
Uploading the Adapter to Huggingface
To automatically upload the adapter to Huggingface, make sure that:- You use a
WRITEtoken as theHUGGING_FACE_HUB_TOKENsecret. - You are passing in the
hf_org_idparameter in thecreate_fine_tuning_jobfunction.
{HF_ORG_IF}/{job_name}_{job_id} format. So for the above example the adapter
would get uploaded to {ORG_ID_HERE}/fine-tuning-job_unique_id. The repo would be private by default.
Model Deployment
- Clone Lorax repository:
- Use the following command to deploy
The below deploy command deploys lorax instance in default environment. Make sure you have created the hugging-face-secret in default environment. You can create secret in default environment by adding
--env default flag in the secret creation command.- Get your deployment url using
tensorkube deployment list.
Inference
You can now use the deployment URL to make inference requests. Here is an example usingcurl. This will query the base model without any adapters.

