Skip to content

Registry: Add cloudpickle support#378

Draft
AgentDosaku wants to merge 1 commit intodevfrom
fix/issue-309-default-materializer
Draft

Registry: Add cloudpickle support#378
AgentDosaku wants to merge 1 commit intodevfrom
fix/issue-309-default-materializer

Conversation

@AgentDosaku
Copy link
Collaborator

Summary

Adds a default_materializer argument to Registry / _RegistryCore so users can opt into a fallback serializer (e.g. ZenML CloudpickleMaterializer) when no type-specific materializer is registered.

This enables saving/loading callables and custom classes without first registering explicit materializers for each type.

Closes #309

What changed

  • Added default_materializer to:
    • Registry.__init__
    • _RegistryCore.__init__
  • Updated materializer resolution order in _find_materializer to include registry-level fallback:
    1. explicitly provided materializer
    2. registered materializer for object type
    3. registered materializer for base classes
    4. registry default_materializer fallback
    5. object self-materializer fallback
  • Added load-time fallback behavior for non-importable classes/functions (works with cloudpickle-backed artifacts).
  • Added focused unit tests covering the new fallback behavior.

Usage examples (verified)

I ran these examples locally on this branch and confirmed they execute successfully.

from mindtrace.registry import Registry
from zenml.materializers.cloudpickle_materializer import CloudpickleMaterializer

registry = Registry(
    backend="~/.cache/mindtrace/my_registry",
    version_objects=True,
    default_materializer=CloudpickleMaterializer,
)

# Lambda/function serialization
f = lambda x: x + 1
registry.save("test:lambda", f, version="1.0.0")
assert registry.load("test:lambda", version="1.0.0")(1) == 2
from mindtrace.registry import Registry
from zenml.materializers.cloudpickle_materializer import CloudpickleMaterializer

class Point:
    def __init__(self, x):
        self.x = x

    def __reduce__(self):
        return (Point, (self.x,))

registry = Registry(
    backend="~/.cache/mindtrace/my_registry",
    version_objects=True,
    default_materializer=CloudpickleMaterializer,
)

registry.save("test:point", Point(5), version="1.0.0")
point = registry.load("test:point", version="1.0.0")
assert point.x == 5

Testing

  • pytest -q tests/unit/mindtrace/registry/core/test_registry.py -k "default_materializer or save_without_materializer"
  • ds test --unit (full unit suite on branch)

@AgentDosaku AgentDosaku changed the title feat(registry): add default_materializer fallback support Add cloudpickle support to Registry Feb 26, 2026
@AgentDosaku AgentDosaku changed the title Add cloudpickle support to Registry Registry: Add cloudpickle support Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add pickle / cloudpickle default support to the Registry

1 participant