#3175 Compile byte code during ImageSpec install
Pull request opened by
thomasjpfan
Why are the changes needed?
This PR adds byte code compiling to the image spec, which reduces runtime at the cost of a slightly bigger image. With this simple workflow:
from flytekit import ImageSpec, task
image = ImageSpec(
name="bytecode",
registry="localhost:30000",
packages=["torch"],
)
@task(container_image=image)
def hello() -> float:
import torch
x = torch.ones(10, dtype=torch.float32)
return x.sum().item()
I got these runtimes:
| new node | image on node | image size | |
| ---------- | ------------- | ---------- | ------ |
| compile | 46s | 20s | 5.86GB |
| no-compile | 1m5s | 33s | 5.72GB |
What changes were proposed in this pull request?
Adds
UV_COMPILE_BYTECODE=1
to the image builder.
How was this patch tested?
I ran the workflow above and benchmarked the times.
Summary by Bito
This PR introduces bytecode compilation to the ImageSpec installation process by adding the UV_COMPILE_BYTECODE flag in the image builder file. The modification optimizes image build configuration as shown by benchmarks, enhancing functionality while remaining straightforward and testable.
Unit tests added: False
Estimated effort to review (1-5, lower is better): 1
flyteorg/flytekit