mirror of
https://github.com/zama-ai/concrete.git
synced 2026-04-17 03:00:54 -04:00
feat(frontend-python): implement dumping/loading of auto rounders
This commit is contained in:
@@ -4,7 +4,7 @@ Declaration of `round_bit_pattern` function, to provide an interface for rounded
|
||||
|
||||
import threading
|
||||
from copy import deepcopy
|
||||
from typing import Any, Callable, Iterable, List, Tuple, Union
|
||||
from typing import Any, Callable, Dict, Iterable, List, Tuple, Union
|
||||
|
||||
import numpy as np
|
||||
|
||||
@@ -123,6 +123,36 @@ class AutoRounder:
|
||||
|
||||
# pylint: enable=protected-access,too-many-branches
|
||||
|
||||
def dump_dict(self) -> Dict:
|
||||
"""
|
||||
Dump properties of the rounder to a dict.
|
||||
"""
|
||||
|
||||
return {
|
||||
"target_msbs": self.target_msbs,
|
||||
"is_adjusted": self.is_adjusted,
|
||||
"input_min": self.input_min,
|
||||
"input_max": self.input_max,
|
||||
"input_bit_width": self.input_bit_width,
|
||||
"lsbs_to_remove": self.lsbs_to_remove,
|
||||
}
|
||||
|
||||
@classmethod
|
||||
def load_dict(cls, properties: Dict) -> "AutoRounder":
|
||||
"""
|
||||
Load previously dumped rounder.
|
||||
"""
|
||||
|
||||
result = AutoRounder(target_msbs=properties["target_msbs"])
|
||||
|
||||
result.is_adjusted = properties["is_adjusted"]
|
||||
result.input_min = properties["input_min"]
|
||||
result.input_max = properties["input_max"]
|
||||
result.lsbs_to_remove = properties["lsbs_to_remove"]
|
||||
result.input_bit_width = properties["input_bit_width"]
|
||||
|
||||
return result
|
||||
|
||||
|
||||
def round_bit_pattern(
|
||||
x: Union[int, np.integer, List, np.ndarray, Tracer],
|
||||
|
||||
Reference in New Issue
Block a user