Welcome back to our free LLMOps course. The previous article discussed LLMOps systems and explored how to evaluate them. Let’s get our hands dirty and delve into building automation and orchestration with pipelines.
Training LLMs involves multiple tuning iterations to achieve optimal performance. That’s why we need to automate the training and tuning processes. We’ll use open-source Kubeflow to automate the process of running experiments.
LLMOps Workflows with Pipelines
Before diving into code, let’s revisit the concept of LLMO workflows, which is a process involving several steps:
- Data Acquisition: In this process, you collect the raw data to train your model.
- Data Processing & Feature Engineering: This involves cleaning and preparing the data and extracting features that will be useful for training.
- Model Training, where the model learns from your data.
- Model Evaluation: assess the model’s performance on a separate evaluation dataset.
- Model Deployment: Once the model meets the requirements, you deploy it to production.
- Monitoring & Feedback continuously monitors the model’s performance, i.e., correctness, accuracy, etc.

You can automate this entire workflow using pipelines!
Orchestration vs. Automation
Many confuse orchestration with automation, which are different but related.
- Orchestration specifies the order of execution for the steps in your workflow. It defines which step needs to run first, followed by the next one, and so on.
- Automation is about writing automation scripts to manage individual steps for you. It automates the execution process.
Frameworks like Airflow and Kubeflow Pipelines are popular for orchestrating and automating LLM model training or fine-tuning workflows. Also, libraries like Kubeflow Pipelines provide a user-friendly Domain-Specific Language (DSL) designed to construct machine learning pipelines.

Building a Simple Pipeline
Let’s build a basic example to illustrate the concepts. We’ll use a hypothetical Python function that inputs a string, greets the recipient by name, and returns a response.
Here’s the gist of the code (replace placeholder_1 and placeholder_2 with the actual code):
# Component 1: Say hello
def say_hello(recipient):
return f"Hello, {recipient}!"
# Component 2: Ask how are you
def how_are_you(text):
return f"{text} How are you?"
# Pipeline definition
@dsl.pipeline
def hello_pipeline(recipient):
greeting = say_hello(recipient)
question = how_are_you(greeting)
return question
# Compile the pipeline (replace with placeholder_1)
placeholder_1
# Run the pipeline with a recipient name (replace with placeholder_2)
placeholder_2This example demonstrates the core concepts of components and pipelines. We define functions as components and use the pipeline decorator to specify the execution order.
Next, let’s explore using these concepts to build a real-world LLM finetuning pipeline!
Fine-tuning a Large Language Model with Pipelines
Once you build a pipeline, you can reuse it for various purposes. Imagine you’ve created a question-and-answer (Q&A) language model and its corresponding pipeline for processing data, training, and evaluation. A co-worker with a similar Q&A project could reuse your pipeline with minimal modifications.
Let’s explore how we can reuse an open-source pipeline to fine-tune a pre-trained foundation model like PaLM from Google AI. Fine-tuning allows you to customize a powerful model for your specific task.
I will use Kubeflow Pipelines (KFP) here, but the same concepts apply to other frameworks. Remember the two Python functions we created in the previous example (say_hello and how_are_you)? We’ll replace those with actual data processing, training, and evaluation components.
Key Points to Consider:
- The pipeline reuses code from the previous article, where we generated training and evaluation data in JSONLine format.
- We’ll specify arguments like the model name and hyperparameters for fine-tuning.
- KFP generates a YAML file containing the pipeline configuration, including dependencies and execution order.
We won’t delve into the entire code for brevity, but here’s a breakdown of the key steps:
- Import Libraries: Import necessary libraries like KFP and Kubeflow.
- Define Pipeline Arguments: Specify arguments like the project ID, region, model name, and data locations.
- Create Components: Develop components for data processing, training (using PaLM’s fine-tuning capabilities), and evaluation.
- Build the Pipeline: Assemble the pipeline using KFP’s DSL, specifying the order of component execution and passing data between them.
- Compile and Run: Compile the pipeline using KFP and submit a job to execute it.
fine_tuned_model = "fine_tuned_model.h5" # Placeholder output
return fine_tuned_model
# Evaluation component
@kfp.v2.dsl.component
def evaluate_model(model_path: str, evaluation_data: str) -> kfp.v2.dsl.Metrics:
# Replace this with your evaluation logic
# This step might involve loading the model and evaluation data,
# running predictions, and calculating metrics
accuracy = 0.85 # Placeholder metric
return {"accuracy": accuracy}
# Pipeline workflow
processed_data = preprocess_data(training_data)
fine_tuned_model = finetune_model(
model_name=model_name, training_data=processed_data.output, evaluation_data=evaluation_data
)
evaluation_metrics = evaluate_model(fine_tuned_model.output, evaluation_data)
# Compile and run the pipeline (replace with your specific commands)
kfp.compiler.Compiler().compile(pipeline_func=finetune_llm_pipeline, package_path="llm_finetuning.tar.gz") # Replace with desired package path
# Run the pipeline with specific arguments (replace with your commands)
kfp.v2.client.Client().create_run_from_pipeline_func(
ipeline_func=finetune_llm_pipeline,
arguments={
"project_id": "your-project-id",
"region": "us-central1",
"model_name": "palm-base", # Replace with your model name
"training_data": "gs://your-bucket/training_data.json", # Replace with data path
"evaluation_data": "gs://your-bucket/evaluation_data.json", # Replace with data path
},
)Once you run the pipeline, Kubeflow Pipelines manages the execution. You can monitor the progress and view the results within the Kubeflow UI.
This simplified example highlights how pipelines can automate and streamline LLMs fine-tuning process. You define the workflow, and KFP orchestrates the execution, saving you time and effort.
Conclusion
This article provided a foundational understanding of LLMOps orchestration and automation, covering pipelines using Kubeflow specifically.
In our next article, I will explore how to make predictions, prompting, and ensure the safety of your model to harness the full potential of LLMs.
Stay tuned!
Discover more from AI For Developers
Subscribe to get the latest posts sent to your email.