Skip to content

Commit a290a65

Browse files
committed
[executorch][serialization] Data serialization interface
Introduce data serialization interface. Differential Revision: [D65947145](https://our.internmc.facebook.com/intern/diff/D65947145/) ghstack-source-id: 255575940 Pull Request resolved: #7194
1 parent 9b02899 commit a290a65

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

exir/_serialize/data_serializer.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
from abc import ABC, abstractmethod
2+
from typing import Dict, List, Tuple, Union
3+
4+
from executorch.exir._serialize._cord import Cord
5+
6+
from executorch.exir.schema import Tensor
7+
8+
# Abstract base class that data serializers should adhere to.
9+
class DataSerializer(ABC):
10+
@abstractmethod
11+
def __init__(self) -> None:
12+
"""
13+
This initializer may be overridden in derived classes to hold
14+
the data required for serialization, eg. configurations.
15+
"""
16+
pass
17+
18+
@abstractmethod
19+
def serialize_tensors(self,
20+
tensors: Dict[str, int],
21+
tensor_buffer: List[bytes],
22+
tensor_metadata: Dict[str, Tensor],
23+
) -> Union[Cord, bytes, bytearray]:
24+
"""
25+
Serializes a list of tensor metadata and tensors emitted by ExecuTorch
26+
into a binary blob.
27+
"""
28+
raise NotImplementedError("serialize_data")
29+
30+
@abstractmethod
31+
def deserialize_tensors(self, blob: Union[Cord, bytes, bytearray]) -> Tuple[Dict[str, int], List[bytes], Dict[str, Tensor]]:
32+
"""
33+
Deserializes a blob into a list of tensor metadata and tensors.
34+
"""
35+
raise NotImplementedError("deserialize_data")

0 commit comments

Comments
 (0)