Skip to content

Commit c411ee5

Browse files
committed
Konflux build with CPU torch
Signed-off-by: Haoyu Sun <hasun@redhat.com>
1 parent 50e828c commit c411ee5

11 files changed

Lines changed: 263 additions & 621 deletions

.tekton/lightspeed-stack-pull-request.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ spec:
3434
- name: build-source-image
3535
value: 'true'
3636
- name: prefetch-input
37-
value: '[{"type": "rpm", "path": "."}, {"type": "pip", "path": ".", "allow_binary": "true", "requirements_files": ["requirements.x86_64.txt", "requirements.aarch64.txt", "requirements.hermetic.txt"]}]'
37+
value: '[{"type": "rpm", "path": "."}, {"type": "pip", "path": ".", "allow_binary": "true", "requirements_files": ["requirements.x86_64.txt", "requirements.aarch64.txt", "requirements.hermetic.txt", "requirements.torch.txt"]}]'
3838
- name: hermetic
3939
value: 'true'
4040
- name: dockerfile

.tekton/lightspeed-stack-push.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ spec:
3131
- name: build-source-image
3232
value: 'true'
3333
- name: prefetch-input
34-
value: '[{"type": "rpm", "path": "."}, {"type": "pip", "path": ".", "allow_binary": "true", "requirements_files": ["requirements.x86_64.txt", "requirements.aarch64.txt", "requirements.hermetic.txt"]}]'
34+
value: '[{"type": "rpm", "path": "."}, {"type": "pip", "path": ".", "allow_binary": "true", "requirements_files": ["requirements.x86_64.txt", "requirements.aarch64.txt", "requirements.hermetic.txt", "requirements.torch.txt"]}]'
3535
- name: hermetic
3636
value: 'true'
3737
- name: dockerfile

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ COPY ${LSC_SOURCE_DIR}/pyproject.toml ${LSC_SOURCE_DIR}/LICENSE ${LSC_SOURCE_DIR
3030
# PIP_FIND_LINKS=/cachi2/output/deps/pip
3131
# PIP_NO_INDEX=true
3232
RUN if [ -f /cachi2/cachi2.env ]; then \
33-
. /cachi2/cachi2.env && uv venv --seed --no-index --find-links ${PIP_FIND_LINKS} && . .venv/bin/activate && pip install --no-index --find-links ${PIP_FIND_LINKS} -r requirements.$(uname -m).txt; \
33+
. /cachi2/cachi2.env && uv venv --seed --no-index --find-links ${PIP_FIND_LINKS} && . .venv/bin/activate && pip install --no-index --find-links ${PIP_FIND_LINKS} -r requirements.$(uname -m).txt -r requirements.torch.txt; \
3434
else \
3535
uv sync --locked --no-dev --group llslibdev; \
3636
fi

Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ PATH_TO_PLANTUML := ~/bin
44
# Python registry to where the package should be uploaded
55
PYTHON_REGISTRY = pypi
66

7+
# PyTorch version
8+
TORCH_VERSION := 2.7.1
9+
710

811
run: ## Run the service locally
912
uv run src/lightspeed_stack.py
@@ -98,6 +101,13 @@ distribution-archives: ## Generate distribution archives to be uploaded into Pyt
98101
upload-distribution-archives: ## Upload distribution archives into Python registry
99102
uv run python -m twine upload --repository ${PYTHON_REGISTRY} dist/*
100103

104+
konflux-requirements: ## generate hermetic requirements.*.txt file for konflux build
105+
uv pip compile pyproject.toml -o requirements.x86_64.txt --generate-hashes --group llslibdev --python-platform x86_64-unknown-linux-gnu --torch-backend cpu --python-version 3.12
106+
uv pip compile pyproject.toml -o requirements.aarch64.txt --generate-hashes --group llslibdev --python-platform aarch64-unknown-linux-gnu --torch-backend cpu --python-version 3.12
107+
./scripts/remove_torch_deps.sh requirements.x86_64.txt
108+
./scripts/remove_torch_deps.sh requirements.aarch64.txt
109+
echo "torch==${TORCH_VERSION}" | uv pip compile - -o requirements.torch.txt --generate-hashes --python-version 3.12 --torch-backend cpu --emit-index-url --no-deps --index-url https://download.pytorch.org/whl/cpu
110+
101111
help: ## Show this help screen
102112
@echo 'Usage: make <OPTIONS> ... <TARGETS>'
103113
@echo ''

README.md

Lines changed: 63 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
[![Tag](https://img.shields.io/github/v/tag/lightspeed-core/lightspeed-stack)](https://github.com/lightspeed-core/lightspeed-stack/releases/tag/0.3.0)
1010

1111
Lightspeed Core Stack (LCS) is an AI-powered assistant that provides answers to product questions using backend LLM services, agents, and RAG databases.
12-
12+
1313
The service includes comprehensive user data collection capabilities for various types of user interaction data, which can be exported to Red Hat's Dataverse for analysis using the companion [lightspeed-to-dataverse-exporter](https://github.com/lightspeed-core/lightspeed-to-dataverse-exporter) service.
1414

1515

1616
<!-- vim-markdown-toc GFM -->
1717

18+
* [lightspeed-stack](#lightspeed-stack)
19+
* [About The Project](#about-the-project)
1820
* [Architecture](#architecture)
1921
* [Prerequisites](#prerequisites)
2022
* [Installation](#installation)
@@ -50,7 +52,9 @@ The service includes comprehensive user data collection capabilities for various
5052
* [Running Linux container image](#running-linux-container-image)
5153
* [Building Container Images](#building-container-images)
5254
* [Llama-Stack as Separate Service (Server Mode)](#llama-stack-as-separate-service-server-mode)
55+
* [macOS (arm64)](#macos-arm64)
5356
* [Llama-Stack as Library (Library Mode)](#llama-stack-as-library-library-mode)
57+
* [macOS](#macos)
5458
* [Verify it's running properly](#verify-its-running-properly)
5559
* [Custom Container Image](#custom-container-image)
5660
* [Endpoints](#endpoints)
@@ -82,6 +86,11 @@ The service includes comprehensive user data collection capabilities for various
8286
* [Query endpoint REST API handler](#query-endpoint-rest-api-handler)
8387
* [Streaming query endpoint REST API handler](#streaming-query-endpoint-rest-api-handler)
8488
* [Versioning](#versioning)
89+
* [Konflux](#konflux)
90+
* [Updating Dependencies for Hermetic Builds](#updating-dependencies-for-hermetic-builds)
91+
* [When to Update Dependency Files](#when-to-update-dependency-files)
92+
* [Updating Python Dependencies](#updating-python-dependencies)
93+
* [Updating RPM Dependencies](#updating-rpm-dependencies)
8594

8695
<!-- vim-markdown-toc -->
8796

@@ -116,7 +125,7 @@ Lightspeed Core Stack is based on the FastAPI framework (Uvicorn). The service i
116125

117126
You will need an API key from one of these providers to run LightSpeed Stack.
118127

119-
For example, if you choose to use OpenAI:
128+
For example, if you choose to use OpenAI:
120129

121130
1. **Create an account** at [platform.openai.com](https://platform.openai.com)
122131
2. **Add payment information** (new accounts receive free trial credits)
@@ -136,7 +145,7 @@ Installation steps depends on operation system. Please look at instructions for
136145

137146
# Run LCS locally
138147

139-
To quickly get hands on LCS, we can run it using the default configurations provided in this repository:
148+
To quickly get hands on LCS, we can run it using the default configurations provided in this repository:
140149
0. install dependencies using [uv](https://docs.astral.sh/uv/getting-started/installation/) `uv sync --group dev --group llslibdev`
141150
1. check Llama stack settings in [run.yaml](run.yaml), make sure we can access the provider and the model, the server shoud listen to port 8321.
142151
2. export the LLM token env var that Llama stack requires. for OpenAI, we set the env var by `export OPENAI_API_KEY=sk-xxxxx`
@@ -151,7 +160,7 @@ To quickly get hands on LCS, we can run it using the default configurations prov
151160
152161
## LLM Compatibility
153162
154-
Lightspeed Core Stack (LCS) supports the large language models from the providers listed below.
163+
Lightspeed Core Stack (LCS) supports the large language models from the providers listed below.
155164
156165
| Provider | Model | Tool Calling | provider_type | Example |
157166
| -------- | ---------------------------------------------- | ------------ | -------------- | -------------------------------------------------------------------------- |
@@ -172,7 +181,7 @@ For details of OpenAI model capabilities, please refer to https://platform.opena
172181
173182
The LLM provider and model are set in the configuration file for Llama Stack. This repository has a Llama stack configuration file [run.yaml](examples/run.yaml) that can serve as a good example.
174183
175-
The LLM providers are set in the section `providers.inference`. This example adds a inference provider "openai" to the llama stack. To use environment variables as configuration values, we can use the syntax `${env.ENV_VAR_NAME}`.
184+
The LLM providers are set in the section `providers.inference`. This example adds a inference provider "openai" to the llama stack. To use environment variables as configuration values, we can use the syntax `${env.ENV_VAR_NAME}`.
176185
177186
For more details, please refer to [llama stack documentation](https://llama-stack.readthedocs.io/en/latest/distributions/configuration.html#providers). Here is a list of llamastack supported providers and their configuration details: [llama stack providers](https://llama-stack.readthedocs.io/en/latest/providers/inference/index.html#providers)
178187
@@ -805,7 +814,7 @@ the following form:
805814
[testpypi]
806815
username = __token__
807816
password = pypi-{your-API-token}
808-
817+
809818
[pypi]
810819
username = __token__
811820
password = pypi-{your-API-token}
@@ -927,3 +936,51 @@ The version X.Y.Z indicates:
927936
* X is the major version (backward-incompatible),
928937
* Y is the minor version (backward-compatible), and
929938
* Z is the patch version (backward-compatible bug fix).
939+
940+
# Konflux
941+
942+
The official image of Lightspeed Core Stack is built on [Konflux](https://konflux-ui.apps.kflux-prd-rh02.0fk9.p1.openshiftapps.com/ns/lightspeed-core-tenant/applications/lightspeed-stack).
943+
We have both x86_64 and ARM64 images.
944+
945+
## Updating Dependencies for Hermetic Builds
946+
947+
Konflux builds run in **hermetic mode** (air-gapped from the internet), so all dependencies must be prefetched and locked. When you add or update dependencies, you need to regenerate the lock files.
948+
949+
### When to Update Dependency Files
950+
951+
Update these files when you:
952+
- Add/remove/update Python packages in the project
953+
- Add/remove/update RPM packages in the Containerfile
954+
- Change the base image version
955+
956+
### Updating Python Dependencies
957+
958+
**Quick command:**
959+
```shell
960+
make konflux-requirements
961+
```
962+
963+
This generates three platform-specific requirements files:
964+
- `requirements.x86_64.txt` - x86_64 packages (excludes torch)
965+
- `requirements.aarch64.txt` - ARM64 packages (excludes torch)
966+
- `requirements.torch.txt` - CPU variant of torch (shared by both platforms)
967+
968+
### Updating RPM Dependencies
969+
970+
**Prerequisites:** Install [rpm-lockfile-prototype](https://github.com/konflux-ci/rpm-lockfile-prototype?tab=readme-ov-file#installation)
971+
972+
**Steps:**
973+
974+
1. **List your RPM packages** in `rpms.in.yaml` under the `packages` field
975+
976+
2. **If you changed the base image**, extract its repo file:
977+
```shell
978+
podman run -it $BASE_IMAGE cat /etc/yum.repos.d/ubi.repo > ubi.repo
979+
```
980+
981+
3. **Generate the lock file**:
982+
```shell
983+
rpm-lockfile-prototype --image $BASE_IMAGE rpms.in.yaml
984+
```
985+
986+
This creates `rpms.lock.yaml` with pinned RPM versions.

pyproject.toml

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,9 @@ name = "pytorch-cpu"
8888
url = "https://download.pytorch.org/whl/cpu"
8989
explicit = true
9090

91-
[[tool.uv.index]]
92-
name = "pypi-default"
93-
url = "https://pypi.org/simple"
94-
explicit = true
9591
[tool.uv.sources]
9692
torch = [
9793
{ index = "pytorch-cpu", group = "llslibdev" },
98-
{ index = "pypi-default", group = "llslibdev-hermetic" }
99-
]
100-
[tool.uv]
101-
conflicts = [
102-
[
103-
{ group = "llslibdev" },
104-
{ group = "llslibdev-hermetic" },
105-
],
10694
]
10795

10896
[dependency-groups]
@@ -174,50 +162,6 @@ llslibdev = [
174162
"blobfile>=3.0.0",
175163
"psutil>=7.0.0",
176164
]
177-
llslibdev-hermetic = [
178-
# the same as llslibdev, just using default index.
179-
"matplotlib>=3.10.0",
180-
"pillow>=11.1.0",
181-
"pandas>=2.2.3",
182-
"scikit-learn>=1.5.2",
183-
"psycopg2-binary>=2.9.10",
184-
# API eval: inline::meta-reference
185-
"tree_sitter>=0.24.0",
186-
"pythainlp>=3.0.10",
187-
"langdetect>=1.0.9",
188-
"emoji>=2.1.0",
189-
"nltk>=3.8.1",
190-
# API inference: remote::gemini
191-
"litellm>=1.75.5.post1",
192-
# API inference: inline::sentence-transformers
193-
"sentence-transformers>=5.0.0",
194-
# API vector_io: inline::faiss
195-
"faiss-cpu>=1.11.0",
196-
# API scoring: inline::basic
197-
"requests>=2.32.4",
198-
# API datasetio: inline::localfs
199-
"aiosqlite>=0.21.0",
200-
# API datasetio: remote::huggingface
201-
"datasets>=3.6.0",
202-
# API telemetry: inline::meta-reference
203-
"opentelemetry-sdk>=1.34.1",
204-
"opentelemetry-exporter-otlp>=1.34.1",
205-
# API tool_runtime: inline::rag-runtime
206-
"transformers>=4.34.0",
207-
"numpy==2.2.6",
208-
# API tool_runtime: remote::model-context-protocol
209-
"mcp>=1.9.4",
210-
# API post_training: inline::huggingface
211-
"torch==2.7.1; sys_platform == 'linux'",
212-
"trl>=0.18.2",
213-
"peft>=0.15.2",
214-
# Other
215-
"autoevals>=0.0.129",
216-
"fire>=0.7.0",
217-
"opentelemetry-instrumentation>=0.55b0",
218-
"blobfile>=3.0.0",
219-
"psutil>=7.0.0",
220-
]
221165

222166
build = [
223167
"build>=1.2.2.post1",

0 commit comments

Comments
 (0)