> ## Documentation Index
> Fetch the complete documentation index at: https://docs.shaktistudio.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Adding a Custom Model

> Prepare and add a custom model or custom pipeline to the platform using the standard model interface and runtime configuration.

For **custom models or custom pipelines**, you must **prepare the model configuration before adding the model to the platform**. This includes defining the model logic, dependencies, and runtime environment. The platform expects all required files to be packaged together and provided as a single artifact.

This page describes how to implement the model interface, define runtime configuration, package your model, and add it through the UI.

## Model interface (`model.py`)

Your custom model must implement a standard interface so the platform can load and run it correctly.

**Method requirements:**

* **`load()`** – Handles model initialization and weight loading
* **`preprocess()`** – Optional input preprocessing
* **`predict()`** – Core inference logic
* **`postprocess()`** – Optional output formatting

Example:

```python theme={null}
class Model:
    def __init__(self):
        self.model_ = None

    def load(self):
        # Initialize or load model weights
        self.model_ = "Model Initialization"

    def preprocess(self, request):
        """
        Preprocess the incoming request.
        Input can be a Pydantic BaseModel, dict, or string.
        """
        return request

    def predict(self, request):
        # Run inference
        output = self.model_.predict()
        return output

    def postprocess(self, request):
        # Postprocess the model output
        return request
```

## Runtime configuration (`config.yaml`)

The `config.yaml` file defines the execution environment for the custom model.

**Key sections:**

* **`python_version`** – Python runtime version
* **`environment_variables`** – Custom environment variables (if any)
* **`requirements`** – Python dependencies
* **`system_packages`** – OS-level packages
* **`custom_setup_script`** – Optional setup script executed during build

Example:

```yaml theme={null}
python_version: "3.10"

environment_variables: {}

requirements:
  - accelerate==0.20.3
  - bitsandbytes==0.39.1
  - peft==0.3.0
  - protobuf==4.23.3
  - sentencepiece==0.1.99
  - torch==2.0.1
  - transformers==4.30.2

system_packages:
  - wget
  - curl

custom_setup_script: "script.sh"
```

## Packaging the custom model

Before adding the model to the platform, package all required files into a single artifact.

<Steps>
  <Step title="Create a single directory">
    Place the following in one folder:

    * `model.py`
    * `config.yaml`
    * Any additional scripts or assets (e.g. `script.sh`)
  </Step>

  <Step title="Compress the directory">
    Create a **ZIP file** containing the directory contents.
  </Step>

  <Step title="Upload the ZIP">
    Upload the ZIP to one of the supported model sources:

    * **AWS S3**
    * **GCP GCS**
    * **Public URL**
  </Step>
</Steps>

<Note>
  Upload your trained model to **AWS S3** or **GCP GCS**, share the access credentials, and the platform will compile and prepare it for deployment. Models built to your specifications are integrated into the platform.
</Note>

## Adding the custom model to the platform

When adding the model in the UI, select the appropriate **Model Source**, set the **Model Path** to the location of the ZIP file, and choose **Custom Pipeline / Custom Model** as the model type. The platform unpacks the archive, sets up the environment, and loads the model using your configuration.

<Steps>
  <Step title="Open Add Model">
    Navigate to [**My Models**](https://shaktistudio.ai/my-models) and click **Add a Model** (top-right).
  </Step>

  <Step title="Enter model details">
    * Provide a **Model Name**.
    * Select **Model Source**: **Hugging Face** or **AWS/GCP bucket** (use the source where you uploaded the ZIP).
    * Enter the **Model Path** (e.g. S3 URI, GCS URI, or public URL to the ZIP).
    * Select the linked **[Cloud Credentials](integrations/secrets)** if required.
          <img src="https://mintcdn.com/simplismart-2/QbPeO9AWw50A_ecx/images/model-suite/custom-model/1-add-model.png?fit=max&auto=format&n=QbPeO9AWw50A_ecx&q=85&s=0b69589806d73c462c71061cfe857170" alt="" width="2848" height="1458" data-path="images/model-suite/custom-model/1-add-model.png" />
  </Step>

  <Step title="Set model class">
    Under **Model Class**, choose **Custom Pipeline** (or **Custom Model**).
  </Step>

  <Step title="Select Optimisation infrastructure">
    * Select a **Accelerator type** based on your model’s size and compute requirements.
  </Step>

  <Step title="Add the model">
    Click **Add Model** to start compilation. The platform will unpack the archive, set up the environment, and load the model.
  </Step>
</Steps>

### LoRA Configuration (Optional)

LoRA (Low-Rank Adaptation) allows loading fine-tuned adapters on top of base models.

* **Enable LoRA** – Toggle to enable or disable LoRA.
* **LoRA Config Method:**
  * **Via LoRA List** – Use pre-registered LoRA adapters
  * **Via LoRA Repo** – Load directly from a repository

Use **Add LoRA Path** to attach multiple adapters if needed.

<img src="https://mintcdn.com/simplismart-2/QbPeO9AWw50A_ecx/images/model-suite/optimise-a-model/9-lora-config.png?fit=max&auto=format&n=QbPeO9AWw50A_ecx&q=85&s=6630c6603fd6c60d3efc8a7de8e12e68" alt="LoRA configuration with enable toggle and config method" width="2788" height="732" data-path="images/model-suite/optimise-a-model/9-lora-config.png" />

When adding a LoRA path:

* **Source (Required)** – Where the LoRA weights are stored (e.g. AWS (IAM Credentials))
* **Secret (Required)** – Credentials used to access the LoRA source
* **Path (Required)** – Path to the LoRA adapter location

<img src="https://mintcdn.com/simplismart-2/QbPeO9AWw50A_ecx/images/model-suite/optimise-a-model/10-lora-repo.png?fit=max&auto=format&n=QbPeO9AWw50A_ecx&q=85&s=6a0da2e70a217660a06289bc616541bd" alt="LoRA path configuration with source, secret, and path" width="2824" height="1122" data-path="images/model-suite/optimise-a-model/10-lora-repo.png" />

***

#### Extra Parameters

Based on your model pipeline, you can add extra parameters here in the JSON format.
