Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to mark function outputs as unserializable #743

Open
skrawcz opened this issue Mar 5, 2024 · 2 comments
Open

Add ability to mark function outputs as unserializable #743

skrawcz opened this issue Mar 5, 2024 · 2 comments
Labels

Comments

@skrawcz
Copy link
Collaborator

skrawcz commented Mar 5, 2024

Is your feature request related to a problem? Please describe.
In Parallel & Collect blocks, there could be a process boundary. Inputs that are invariant to each chunk of the block need to be serialized and deserialized -- but for things like clients (e.g. openai, db client) those objects aren't serializable and things break.

Describe the solution you'd like

@unserializable
def client() -> object:
   """Some client, e.g. openai, etc"""
   return ... 

Then Hamilton will know that for each parallel block, we rerun this function, versus trying to run it once and trying to serialize and deserialize it.

Describe alternatives you've considered
You can get around this by making the client() function depend on some part of the parallel block (client(some_dep: object)) thereby forcing it to be run each block.

Additional context
This would be a quality of life improvement.

@elijahbenizzy
Copy link
Collaborator

Similar to this: #90

@skrawcz
Copy link
Collaborator Author

skrawcz commented Mar 5, 2024

Another alternative is to create a wrapper object and use that instead:

class SerializeableOpenAIClient:
    def __init__(self):
        self.client = OpenAI()

    def __getstate__(self):
        return {}

    def __setstate__(self, d):
        self.client = OpenAI()

def client() -> SerializeableOpenAIClient:
    return SerializeableOpenAIClient()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants