Skip to content

Commit

Permalink
chore: can't pickle executor we need to reinitialize it
Browse files Browse the repository at this point in the history
  • Loading branch information
jfrery committed Nov 18, 2024
1 parent 10138be commit 76f409a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/concrete/ml/torch/hybrid_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,32 @@ def __init__(
self.optimized_linear_execution = optimized_linear_execution
self.executor: Optional[GLWELinearLayerExecutor] = None

def __getstate__(self):
"""Define how the instance should be pickled.
Returns:
dict: A dictionary containing the instance's serializable state
"""
state = self.__dict__.copy()

# Remove the unpicklable executor attribute
if "executor" in state:
del state["executor"]

return state

def __setstate__(self, state):
"""Define how the instance should be unpickled.
Args:
state (dict): A dictionary containing the instance's serialized state
"""
self.__dict__.update(state)

# Re-initialize the executor
if self.optimized_linear_execution and _HAS_GLWE_BACKEND:
self.executor = GLWELinearLayerExecutor()

def init_fhe_client(
self, path_to_client: Optional[Path] = None, path_to_keys: Optional[Path] = None
): # pragma:no cover
Expand Down

0 comments on commit 76f409a

Please sign in to comment.