cuddly-jelly-27016
04/03/2025, 9:34 AMImageSpec.
This is my pipeline.py inside the workflows-directory:
import datetime
from pathlib import Path
from time import sleep
import flytekit as fl
from flytekit import task, workflow, FlyteDirectory
import polars as pl
image_polars = fl.ImageSpec(registry="localhost:30000", name="polars-image", requirements="uv.lock")
def polars_task(*args, **kwargs):
def decorator(func):
# Combine your pre-filled param with any extra ones passed in
return task(container_image=image_polars, *args, **kwargs)(func)
return decorator
@polars_task()
def create_initial_dataset_task() -> pl.DataFrame:
df = pl.DataFrame(
{
"learner_int_id": [1, 1, 1, 1],
"content_int_id": [10, 20, 30, 40],
"score": [0.5, 0.6, 0.7, 0.8],
"outcome_int": [2, 0, 1, 1],
"play_rank": [1, 2, 3, 4],
}
)
return df
@polars_task()
def create_second_dataset_task() -> pl.DataFrame:
df = pl.DataFrame(
{
"learner_int_id": [2, 2, 2, 2],
"content_int_id": [10, 20, 30, 40],
"score": [0.5, 0.6, 0.7, 0.8],
"outcome_int": [2, 0, 1, 1],
"play_rank": [1, 2, 3, 4],
}
)
return df
@polars_task()
def combine_datasets_task(dataset_1: pl.DataFrame, dataset_2:pl.DataFrame) -> pl.DataFrame:
"""Combine datasets from a folder into a single parquet file."""
combined = pl.concat([dataset_1, dataset_2])
return combined
@polars_task()
def train_model_task(dataset: pl.DataFrame) -> dict:
for i in range(10):
print(f"Epoch {i}...")
sleep(3)
print("Model trained!")
return {"status": "trained", "Other params": {"lr": 0.001, "drop-out": 0.5}}
@task()
def evaluate_model_task(model: dict) -> dict:
print("Testing model...")
lr = model["Other params"]["lr"]
for i in range(10):
print((i + 1) * lr)
return {"datetime": datetime.datetime.now().strftime("%Y-%m-%d--%H-%M-%S"), "status": "evaluated",
"my-metric": {"lr": lr, "accuracy": 0.9}}
@task()
def create_folder(name: str) -> FlyteDirectory:
folder = Path(fl.current_context().working_directory) / name
folder.mkdir(parents=True, exist_ok=True)
return FlyteDirectory(path=str(folder))
@workflow
def pipeline() -> None:
ds1 = create_initial_dataset_task()
ds2 = create_second_dataset_task()
dataset = combine_datasets_task(ds1, ds2)
model = train_model_task(dataset)
metrics = evaluate_model_task(model)
if name == '__main__':
# folder = Path("data") / datetime.datetime.now().strftime("%Y-%m-%d--%H-%M-%S")
pipeline()
The uv.lock contains the dependencies for flytekit and polars.
Running pyflyte run --remote -p toy-pipeline -d development workflows/pipeline.py pipeline builds the docker image as the tasks require the image. I can see it in my local docker registry.
In the dashboard the two first tasks exit with errors (one "Failed" another "Aborted"):
• Failed: Grace period [3m0s] exceeded|containers with unready status: [a5vw9jzmsw52954q9526-n1-0]|Back-off pulling image "localhost30000/polars imageQq6EgwGJ2Z2u5Oi7XS1WBg"
• Aborted (no error message)
[Image](https://private-user-images.githubusercontent.com/9060786/429877807-f0d6cea3-7d27-4c3f-861f-d0155411ec08.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDM2NzM2NjgsIm5iZiI6MTc0MzY3MzM2OCwicGF0aCI6Ii85MDYwNzg2LzQyOTg3NzgwNy1mMGQ2Y2VhMy03ZDI3LTRjM2YtODYxZi1kMDE1NTQxMWVjMDgucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDQwMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTA0MDNUMDk0MjQ4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9NjJjZTQzMWJjOGMzMmZkMDgxYWVhODNmZTQ5N2RjMzZjOTM1MzVmNmYzYmU0ZmQxMDNjZWY5M2RiNDU5MTk2YyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.KzQecE9UPSFccBXD5EccWGh4jO3_D5HwDq86qbHLDaM)
In the logs of the cluster I can see a better error message:
kuberuntime_image.go:55] "Failed to pull image" err="rpc error: code = NotFound desc = failed to pull and unpack image \"localhost30000/polars imageQq6EgwGJ2Z2u5Oi7XS1WBg\": no match for platform in manifest: not found" image="localhost30000/polars imageQq6EgwGJ2Z2u5Oi7XS1WBg"
I am able to get the workflow to work when building the image myself and supply it to the pyflyte command:
FROM python:3.12-slim-bookworm
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
# Install the project into /app
#WORKDIR /app
# Then, add the rest of the project source code and install it
# Installing separately from its dependencies allows optimal layer caching
COPY pyproject.toml pyproject.toml
COPY uv.lock uv.lock
RUN uv sync --frozen
# Place executables in the environment at the front of the path
# add /app/ in front for it to activate the environment
ENV PATH=".venv/bin:$PATH"
COPY workflows workflows
# This tag is supplied by the build script and will be used to determine the version
# when registering tasks, workflows, and launch plans
ARG tag
ENV FLYTE_INTERNAL_IMAGE=$tag
# Reset the entrypoint, don't invoke uv
# This seems to work though
ENTRYPOINT ["uv", "run"]
1. Remove the polars_task decorator and replace it with normal the task-decorator in pipeline.py
2. docker build --tag localhost:30000/toy-pipeline:latest .
3. docker push localhost:30000/toy-pipeline:latest
4. pyflyte run --image localhost:30000/toy-pipeline:latest --remote -p toy-pipeline -d development workflows/pipeline.py pipeline
<https://private-user-images.githubusercontent.com/9060786/429879575-fa8c36fb-b7ab-4888-9229-0a074c315064.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDM2NzM2NjgsIm5iZiI6MTc0MzY3MzM2OCwicGF0aCI6Ii85MDYwNzg2LzQyOTg3OTU3NS1mYThjMzZmYi1iN2FiLTQ4ODgtOTIyOS0wYTA3NGMzMTUwNjQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDQwMyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTA0MDNUMDk0MjQ4WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9OTY4NTZkMjcyYjE1YTFjY2M0OTAxMjlkZGY4M2EzZTY4NGY1NGUwNDdlNzhkNzY1MmNiMjAyMDRlOTE3NjM5NSZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.SPUhyjHJ218bzSCF7Q6W740U1jDJP76xSSb0udu_NeM|[Image](https://private-user-images.githubusercontent.com/9060786/429879575-fa8c36fb-b7ab-4888-9229-0a074c315064.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDM2NzM2NjgsIm5iZiI6MTc0MzY3MzM2OCwicGF0aCI6Ii85MDYwNzg2LzQyOTg3OTU3NS1mYThjMzZmYi1iN2FiLTQ4ODgtOTIyOS0wYTA3NGMzMTUwNjQucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDQwMyUyRnVzLWVhc3QtM…
flyteorg/flytecuddly-jelly-27016
04/03/2025, 9:42 AM