flyteorg / flyte

Scalable and flexible workflow orchestration platform that seamlessly unifies data, ML and analytics stacks.
https://flyte.org
Apache License 2.0
5.6k stars 614 forks source link

[BUG] Cache doesn't work when running entities by FlyteRemote #5823

Open peterkun23 opened 1 day ago

peterkun23 commented 1 day ago

Describe the bug

Cache hit never happens when running consecutively the following toy example:

from flytekit import task, HashMethod
from typing_extensions import Annotated
from flytekit.remote import FlyteRemote
from flytekit.configuration import Config, PlatformConfig

class VideoRecord:
    def __init__(self, video_path: str):
        self.video_path = video_path

def hash_video_record(record: VideoRecord) -> str:
    return record.video_path

@task(cache=True, cache_version="1.0")
def bar_1(video_record: Annotated[VideoRecord, HashMethod(hash_video_record)]) -> str:
    print("Running bar_1")
    return video_record.video_path

if __name__ == "__main__":
    video_record = VideoRecord("path/to/video")

    remote = FlyteRemote(
        config=Config(
            platform=PlatformConfig(
                endpoint=endpoint,
                insecure=True,
                insecure_skip_verify=True,
            )
        ),
        default_project=default_project,
        default_domain=default_domain,
    )
    entity = remote.fetch_task(name="toy_example.bar_1", version="1.1")
    remote.execute(
        entity=entity,
        inputs={"video_record": video_record},
        wait=True,
        tags=[],
        overwrite_cache=False,
    )

Expected behavior

I would expect a way to make caching work for this use case (either to implement something in the TypeTransforms -FlytePickleTransformerin this case or something else). I believe the problem is that after calling guess_python_type the HashMethod information is already gone.

Additional context to reproduce

No response

Screenshots

No response

Are you sure this issue hasn't been raised already?

Have you read the Code of Conduct?

welcome[bot] commented 1 day ago

Thank you for opening your first issue here! 🛠