This repository contains the source code for the SAP TechEd 2025 demonstration on implementing a "Bring-Your-Own-Model" (BYOM) workflow on SAP AI Core. It provides a complete, end-to-end example of training a text classification model to identify reasons for blocked invoices and deploying it as a scalable inference service.
The project is structured for production-readiness, showcasing best practices such as Docker containerization, pipeline-based orchestration, and API-driven MLOps.
The primary goal of this project is to build an AI model that automatically classifies the reason an invoice is blocked based on its descriptive text. This helps automate a common accounts payable process, reducing manual effort and speeding up resolution times. The classification categories include:
- Price Variance
- Quantity Mismatch
- Missing PO Reference
- Three-Way Match Failure
- Supplier Issues
The entire Machine Learning workflow is orchestrated by SAP AI Core and can be broken down into the following stages:
- Data Preparation: A synthetic dataset mimicking blocked invoice descriptions from an SAP S/4HANA system is generated using
data_preparation.py. - Training Pipeline: A containerized training job is executed on SAP AI Core. It fetches the dataset from an S3 object store, fine-tunes a
microsoft/deberta-v3-basemodel from Hugging Face, evaluates its performance, and registers the final trained model as an artifact. - Serving Pipeline: Another containerized job takes the trained model artifact and deploys it as a RESTful API using KServe. The service is configured for auto-scaling.
- Inference: The deployed API endpoint can then be called with new invoice texts to get real-time predictions for why an invoice is blocked.
.
├── AI Core TechEd.postman_collection.json # Postman collection for interacting with SAP AI Core APIs.
├── data_preparation.py # Script to generate the synthetic invoice dataset.
├── data/ # Contains the generated dataset splits and label map.
│ ├── train.csv
│ ├── validation.csv
│ ├── test.csv
│ └── label_map.json
├── pipelines/ # SAP AI Core workflow and serving templates.
│ ├── training-template.yaml # Argo-based workflow for the training pipeline.
│ └── serving-template.yaml # KServe-based template for the inference service.
├── training/ # Code and configuration for model training.
│ ├── Dockerfile.train # Dockerfile to build the training container.
│ ├── requirements-train.txt # Python dependencies for training.
│ └── train.py # The main training script using Hugging Face Transformers.
└── serving/ # Code and configuration for model serving.
├── Dockerfile.serve # Dockerfile to build the serving container.
├── requirements-serve.txt # Python dependencies for the API.
├── serve.sh # Entrypoint script for the serving container.
└── serving.py # FastAPI application for inference.
- An SAP Business Technology Platform (BTP) account with SAP AI Core configured.
- An S3-compatible object store (e.g., AWS S3) and its access credentials.
- Docker installed and running.
- A container registry (like Docker Hub) to host your images.
- Python 3.10 or later.
- Postman for making API calls.
git clone https://github.com/itsmarlo/teched25-sapaicore-byom.git
cd teched25-sapaicore-byomFirst, generate the synthetic dataset.
python data_preparation.pyThis will create train.csv, validation.csv, test.csv, and label_map.json inside the data/ directory.
Next, upload these files to your S3 bucket. For this example, we assume they are placed under a path like s3://<your-bucket-name>/data/invoices/. Your S3 structure should look like this:
<your-bucket-name>/
└── data/
└── invoices/
├── train.csv
├── validation.csv
├── test.csv
└── label_map.json
You need to build the training and serving Docker images and push them to a registry that your SAP AI Core instance can access.
Important: Before building, update the image names in pipelines/training-template.yaml and pipelines/serving-template.yaml from docker.io/itsmarlo/... to point to your own container registry (e.g., docker.io/<your-username>/...).
# Set your Docker Hub username
export DOCKER_USER=your-docker-hub-username
# Build and push the training image
docker build -t $DOCKER_USER/invoice-train:latest -f training/Dockerfile.train .
docker push $DOCKER_USER/invoice-train:latest
# Build and push the serving image
docker build -t $DOCKER_USER/invoice-serve:latest -f serving/Dockerfile.serve .
docker push $DOCKER_USER/invoice-serve:latestThis project uses a Postman collection to interact with SAP AI Core.
- Import Collection: Import the
AI Core TechEd.postman_collection.jsonfile into Postman. - Set Up Environment: Create a Postman environment and configure the following variables based on your SAP AI Core service key:
AI_API_URL: Theurlfrom your service key.tokenURL: Theuaa.urlfrom your service key.clientId: Theuaa.clientidfrom your service key.clientSecret: Theuaa.clientsecretfrom your service key.
- Update Requests: You will need to modify some of the request bodies in the collection to match your specific setup:
- Set up > Create Object Store Secrets: Replace the placeholder
AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY, andbucketwith your S3 details. - Set up > Onboard GitHub repo: Update the
urland credentials if you are using a fork of this repository. - Training > Register dataset artifact: Update the
urlto point to your S3 path (e.g.,ai://<your-s3-secret-name>/data/invoices/). - Training > Create configuration: After registering the dataset, replace
REPLACE_WITH_DATASET_UUIDwith theidof the artifact you just created. - Serving > Create configuration: After a successful training run, find the model artifact ID from the execution logs or by querying the API. Replace
<MODEL_ARTIFACT_ID>with this ID.
- Set up > Create Object Store Secrets: Replace the placeholder
Run the Postman requests in the following order:
- Authentication: In the
Trainingfolder, runfetch tockento get anaccess_token. This token is automatically stored as a collection variable. - Setup: Execute the requests under the
Set upfolder to configure your resource group, repository, and secrets. - Training:
- Run
Register dataset artifactto make your S3 data known to AI Core. - Run
Create configurationto define the training job parameters. - Run
Trigger executionto start the training pipeline. You can monitor its status in the SAP AI Core UI.
- Run
- Serving:
- Once training is complete, retrieve the model artifact ID from the
outputsof the training execution. - Update and run
Create configurationunder theServingfolder using the new model artifact ID. - Run
Create deploymentto deploy the model as an API endpoint.
- Once training is complete, retrieve the model artifact ID from the
- Inference:
- Find the deployment URL in the SAP AI Core UI or from the deployment details API response.
- Use the
Get predictionrequest (after updating its URL) to send text and receive a classification.
- Orchestration: SAP AI Core
- Containerization: Docker
- ML Framework: PyTorch
- NLP Library: Hugging Face Transformers (
microsoft/deberta-v3-base) - API Framework: FastAPI
- API Client: Postman