Skip to content

Commit

Permalink
Merge pull request #151 from francescortu/add_ellipses_remote_type
Browse files Browse the repository at this point in the history
Add Ellipsis support for remote execution
  • Loading branch information
JadenFiotto-Kaufman authored May 31, 2024
2 parents dd35219 + 5bcace9 commit 77612d6
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/nnsight/pydantics/format/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ def compile(self, graph: Graph, nodes: Dict[str, NodeModel]) -> slice:
self.step.compile(graph, nodes),
)

class EllipsisModel(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
type_name: Literal["ELLIPSIS"] = "ELLIPSIS"

def compile(self, graph: Graph, nodes: Dict[str, NodeModel]) -> type(...): # It will be better to use EllipsisType, but it requires python>=3.10
return ...



class ListModel(BaseModel):
model_config = ConfigDict(arbitrary_types_allowed=True)
Expand Down Expand Up @@ -165,6 +173,14 @@ def compile(self, graph: Graph, nodes: Dict[str, NodeModel]) -> FUNCTION:
),
]

EllipsisType = Annotated[
type(...), # It will be better to use EllipsisType, but it requires python>=3.10
AfterValidator(
lambda value: EllipsisModel()
),
]


ListType = Annotated[list, AfterValidator(lambda value: ListModel(values=value))]

TupleType = Annotated[
Expand Down Expand Up @@ -201,6 +217,7 @@ def compile(self, graph: Graph, nodes: Dict[str, NodeModel]) -> FUNCTION:
ListModel,
TupleModel,
DictModel,
EllipsisModel
],
Field(discriminator="type_name"),
],
Expand All @@ -212,5 +229,6 @@ def compile(self, graph: Graph, nodes: Dict[str, NodeModel]) -> FUNCTION:
ListType,
TupleType,
DictType,
EllipsisType
],
]

0 comments on commit 77612d6

Please sign in to comment.