MCPcopy Create free account
hub / github.com/pytorch/executorch / serialize_alloc_inputs

Method serialize_alloc_inputs

exir/serde/serialize.py:166–192  ·  view source on GitHub ↗

Serialize the inputs to the memory.alloc function. Since there's no specific spec, we jut serialize the inputs with a dummy name. We serialize the AllocSpec into a string "size;dtype"

(
        self, inputs  # pyre-ignore
    )

Source from the content-addressed store, hash-verified

164 return json_acceptable_from_node
165
166 def serialize_alloc_inputs(
167 self, inputs # pyre-ignore
168 ) -> List[schema.NamedArgument]:
169 """
170 Serialize the inputs to the memory.alloc function. Since there's no
171 specific spec, we jut serialize the inputs with a dummy name.
172 We serialize the AllocSpec into a string "size;dtype"
173 """
174 assert len(inputs) == 1
175
176 def serialize_alloc_spec(alloc_spec: memory.AllocSpec) -> schema.Argument:
177 return schema.Argument.create(
178 as_string=f"{alloc_spec[0]};{export_serialize._TORCH_TO_SERIALIZE_DTYPE[alloc_spec[1]].value}"
179 )
180
181 if isinstance(inputs[0], list):
182 return [
183 schema.NamedArgument(name="alloc_list", arg=serialize_alloc_spec(arg))
184 for arg in inputs[0]
185 ]
186 else:
187 # Single value
188 return [
189 schema.NamedArgument(
190 name="alloc_arg", arg=serialize_alloc_spec(inputs[0])
191 )
192 ]
193
194 def serialize_arbitrary_outputs(self, node: torch.fx.Node) -> List[schema.Argument]:
195 meta_val = node.meta["val"]

Callers 1

handle_call_functionMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected