Lesson 2 of 4 Foundation Model Customization Lifecycle

Deploying Parameter-Efficient Fine-Tuning Adapters

This lesson explains parameter-efficient fine-tuning (PEFT), which trains a small number of additional parameters instead of every weight, and its deployment consequences: adapters are small, swappable and can share one base model.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how LoRA adapters work.
  • Serve many adapters on one endpoint with inference components.
  • Choose between merged and dynamic adapters.

How LoRA and adapters work

Low-rank adaptation (LoRA) freezes the base model's weights and trains pairs of small matrices whose product approximates the change each layer needs. Because the matrices have a low rank (for example 8 or 16), they contain a tiny fraction of the model's parameters. QLoRA applies the same idea to a quantised base model, reducing training memory further. More generally, adapters are small trainable modules inserted into or alongside a frozen model.

A LoRA adapter for a model with billions of parameters is typically tens to hundreds of megabytes, compared with tens or hundreds of gigabytes for the model. The adapter can be merged into the base weights to create a standalone model, or kept separate and loaded at inference time on top of the shared base model.

The following diagram shows the frozen weights and the small trainable matrices.

How LoRA adapts a model. The base weight matrix stays frozen, and two small low-rank matrices, A and B, with a rank such as 8 or 16, learn the change each layer needs. The adapter holds a tiny fraction of the parameters, tens to hundreds of megabytes, compared with tens or hundreds of gigabytes for the model.
The matrix sizes are schematic.
True or false

How LoRA works

Exam skills 1.2.4

Test four claims about low-rank adaptation.

Log in to try this activity Interactive activities are free with an account.

Serving many adapters on one endpoint

When an organisation has many variants, for example one per business unit, language or customer, hosting a full model for each is wasteful. On SageMaker AI, the base model is deployed as an inference component on an endpoint, and each adapter is deployed as another inference component that references the base component. Requests name the adapter's inference component, and the serving container applies the adapter to the shared base model, so hundreds of variants can share GPU memory. Large model inference containers with vLLM also support serving multiple LoRA adapters from one model server.

import boto3
sm = boto3.client("sagemaker")
# Adapter inference component that runs on top of an existing base model component
sm.create_inference_component(
    InferenceComponentName="support-adapter-fr",
    EndpointName="llm-endpoint",
    Specification={
        "BaseInferenceComponentName": "llama-base",
        "Container": {"ArtifactUrl": "s3://my-bucket/adapters/support-fr/"},
    },
)
# Invoke the adapter by naming its inference component
smr = boto3.client("sagemaker-runtime")
smr.invoke_endpoint(EndpointName="llm-endpoint", InferenceComponentName="support-adapter-fr",
                    ContentType="application/json", Body=b'{"inputs": "Bonjour ...", "parameters": {"max_new_tokens": 200}}')

The following diagram shows adapter inference components sharing one base model.

Serving many LoRA adapters from one SageMaker AI endpoint. The base model is deployed once as an inference component, and each adapter is another inference component that references it. Requests name the adapter's inference component, and the container applies that adapter to the shared base model.
The adapter names are illustrative.

Merged versus dynamic adapters

A LoRA adapter can be used in two ways. It can be merged into the base model's weights, producing an ordinary model with the adapter's behaviour built in. A merged model has no runtime overhead and needs no special serving support, which suits a single customised variant or importing the model into Bedrock with Custom Model Import. However, every new version means producing and deploying a full-size model.

Alternatively, adapters can be kept separate and loaded dynamically by a serving engine that applies the requested adapter to a shared base model at inference time. One endpoint can then serve many variants, for example one adapter per customer or per task, and a new version is a small artefact that can be deployed in seconds and versioned independently. The cost is a small amount of added latency and a more complex serving configuration. The following table compares the options.

OptionArtifact sizeBest for
Full fine-tuned modelFull model per variantOne variant needing maximum quality change
Merged LoRA modelFull model per variantOne variant; Bedrock Custom Model Import
Dynamic LoRA adaptersSmall adapter per variant, shared baseMany variants, frequent updates, cost efficiency

The following diagram compares the two ways of using an adapter.

Merged and dynamic adapters compared. A merged adapter produces an ordinary model with no runtime overhead, which suits one variant or Custom Model Import, but every update redeploys a full-size model. Dynamic adapters share one base model and are chosen per request, so new versions deploy in seconds, at the cost of slight latency and more complex serving.
Many variants that change often favour dynamic adapters.
Sort into groups

Merge or load dynamically?

Exam skills 1.2.4 · 2.2.3

Decide how each adapter should be served.

Log in to try this activity Interactive activities are free with an account.
Worked example

One model per customer

A software vendor offers each of 120 enterprise customers a model fine-tuned on that customer's support tickets. Hosting 120 full models is too expensive, and customers' adapters are retrained monthly.

The answer is to train LoRA adapters per customer on a common base model and deploy them as adapter inference components on a shared SageMaker AI endpoint, with the application choosing the inference component by customer ID. Each monthly update replaces one small adapter without redeploying the base model.

Check yourself

What does LoRA train, and what stays unchanged?

Show answer

It trains small low-rank matrices (adapters); the base model's weights stay frozen, so many adapters can share one base model.

Exam Tips

Remember for the exam

  • LoRA trains small low-rank matrices; the base model stays frozen.
  • Many variants of one base model: dynamic adapters on shared infrastructure.
  • SageMaker AI inference components can reference a base component to serve adapters.
  • Merged adapters suit a single variant or Custom Model Import.