New RunLLM response generated: >>>*# Question* He...
# runllm-flyte-trial
j
New RunLLM response generated: >>>*# Question* Hello community, I am executing registered flyte tasks by FlyteRemote: https://github.com/flyteorg/flytekit/blob/master/flytekit/remote/remote.py#L1176 Is there a way to have cache hit when having single (PythonPickle) blob as inputs? I have tried to add the Annotated HashMethod to the input types in the flyte task, but it is not working. # Answer To achieve cache hits with a single (PythonPickle) blob as inputs, you need to ensure that the
HashMethod
is correctly applied to the input types in your Flyte task. This involves defining a custom hash function for the PythonPickle object and using the
Annotated
type with
HashMethod
in your task signature. Here's an example of how to do this: 1. Define a Hash Function: Create a function that generates a hash for your PythonPickle object. 2. Annotate Task Input: Use the
Annotated
type with
HashMethod
to annotate the input type in your task.
Copy code
from flytekit import task, workflow, HashMethod
from typing_extensions import Annotated
import pickle

def hash_pickle(obj) -> str:
    return str(hash(pickle.dumps(obj)))

PickleType = Annotated[object, HashMethod(hash_pickle)]

@task(cache=True, cache_version="1.0")
def process_data(data: PickleType) -> str:
    # Process the data
    return "Processed"

@workflow
def wf(data: PickleType) -> str:
    return process_data(data=data)
In this example: -
hash_pickle
is a custom hash function that generates a hash for the pickled object. -
PickleType
is an annotated type that uses
HashMethod
to specify the custom hash function. - The
process_data
task and
wf
workflow use
PickleType
for the input type to ensure caching works correctly. Make sure to register the tasks and workflows with Flyte and execute them using
FlyteRemote
as needed. Would you like more details on any specific part of this process? Sources: - Flyte Caching Documentation - Flyte Issue on Caching with HashMethod - Flyte Example on Task Caching Slack Link https://.slack.com/archives/CP2HDHKE1/p1728033245.602169 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.