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

Error: "No default __reduce__ due to non-trivial __cinit__" #229

Closed
madiator opened this issue Dec 7, 2024 · 4 comments · Fixed by #360
Closed

Error: "No default __reduce__ due to non-trivial __cinit__" #229

madiator opened this issue Dec 7, 2024 · 4 comments · Fixed by #360

Comments

@madiator
Copy link
Contributor

madiator commented Dec 7, 2024

If you have a separate parse_func where you add type annotation to the argument, you get this strange error.

e.g.

from bespokelabs import curator
from datasets import Dataset
from pydantic import BaseModel, Field
from typing import List

# Create a dataset object for the topics you want to create the poems.
topics = Dataset.from_dict({"topic": [
    "Urban loneliness in a bustling city",
    "Beauty of Bespoke Labs's Curator library"
]})

# Define a class to encapsulate a list of poems.
class Poem(BaseModel):
    poem: str = Field(description="A poem.")

class Poems(BaseModel):
    poems_list: List[Poem] = Field(description="A list of poems.")

# removing the type annotation for `poems` works fine.
def parse_func(row, poems: Poems):
    return [
        {"topic": row["topic"], "poem": p.poem} for p in poems.poems_list
    ]

# We define a Prompter that generates poems which gets applied to the topics dataset.
poet = curator.Prompter(
    prompt_func=lambda row: f"Write two poems about {row['topic']}.",
    model_name="gpt-4o-mini",
    response_format=Poems,
    parse_func=parse_func,
)
poem = poet(topics)
print(poem.to_pandas())

Error:

TypeError                                 Traceback (most recent call last)
[<ipython-input-4-38125e72f173>](https://localhost:8080/#) in <cell line: 35>()
     33     parse_func=parse_func,
     34 )
---> 35 poem = poet(topics)
     36 print(poem.to_pandas())

136 frames
/usr/local/lib/python3.10/dist-packages/zmq/backend/cython/socket.cpython-310-x86_64-linux-gnu.so in zmq.backend.cython.socket.Socket.__reduce_cython__()

TypeError: no default __reduce__ due to non-trivial __cinit__
@RyanMarten RyanMarten added bug Something isn't working P1 labels Jan 5, 2025
@RyanMarten RyanMarten added this to the v1 milestone Jan 5, 2025
devin-ai-integration bot added a commit that referenced this issue Jan 6, 2025
- Replace datasets.utils._dill with cloudpickle for better type annotation support
- Update function serialization to handle type annotations properly
- Add cloudpickle dependency to pyproject.toml
- Update documentation and examples with type annotation best practices
- Maintain backward compatibility with existing code patterns

Co-Authored-By: [email protected] <[email protected]>
devin-ai-integration bot added a commit that referenced this issue Jan 7, 2025
- Add dedicated test suite for CustomPickler functionality
- Test path normalization and type annotation support
- Fix return type annotations in test_prompt.py prompt functions
- Add proper type hints for test functions

Part of #229: Implement CustomPickler for function serialization

Co-Authored-By: [email protected] <[email protected]>
@vutrung96
Copy link
Contributor

I cannot reproduce this error. I only get warnings

/home/trung/.cache/pypoetry/virtualenvs/bespokelabs-curator-H3Ru9elj-py3.11/lib/python3.11/site-packages/dill/_dill.py:414: PicklingWarning: Cannot locate reference to <class '__main__.Poem'>.
  StockPickler.save(self, obj, save_persistent_id)
/home/trung/.cache/pypoetry/virtualenvs/bespokelabs-curator-H3Ru9elj-py3.11/lib/python3.11/site-packages/dill/_dill.py:414: PicklingWarning: Cannot pickle <class '__main__.Poem'>: __main__.Poem has recursive self-references that trigger a RecursionError.
  StockPickler.save(self, obj, save_persistent_id)
/home/trung/.cache/pypoetry/virtualenvs/bespokelabs-curator-H3Ru9elj-py3.11/lib/python3.11/site-packages/dill/_dill.py:414: PicklingWarning: Cannot locate reference to <class '__main__.Poems'>.
  StockPickler.save(self, obj, save_persistent_id)
/home/trung/.cache/pypoetry/virtualenvs/bespokelabs-curator-H3Ru9elj-py3.11/lib/python3.11/site-packages/dill/_dill.py:414: PicklingWarning: Cannot pickle <class '__main__.Poems'>: __main__.Poems has recursive self-references that trigger a RecursionError.
  StockPickler.save(self, obj, save_persistent_id)

@vutrung96
Copy link
Contributor

Seems like the warning comes from: uqfoundation/dill#650

@vutrung96
Copy link
Contributor

Per uqfoundation/dill#650 (comment), it seems like this only occurs when the class is declared in main, like @shreyaspimpalgaonkar said.

@vutrung96 vutrung96 added low priority bug and removed bug Something isn't working P1 labels Jan 7, 2025
@vutrung96
Copy link
Contributor

Given that this only throws a warning and is restricted to a certain scenario, I'll lower the priority.

@vutrung96 vutrung96 removed this from the v0.2 milestone Jan 7, 2025
@vutrung96 vutrung96 linked a pull request Jan 13, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants