Skip to content

Commit

Permalink
Remove logic around Initializer-s in adapt_node (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
neNasko1 authored Nov 26, 2024
1 parent 0adb542 commit ca7ebbe
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ Change log

- Value propagation of string tensors no longer raises an erroneous ``ValueError`` in some instances.

**Other changes**

- The adaption logic is not using inferred values as initializers anymore.


0.12.1 (2024-06-18)
-------------------
Expand Down
8 changes: 0 additions & 8 deletions src/spox/_adapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import warnings
from typing import Optional

import numpy as np
import onnx
import onnx.version_converter

Expand All @@ -14,7 +13,6 @@
from ._node import Node
from ._schemas import SCHEMAS
from ._scope import Scope
from ._utils import from_array
from ._var import Var


Expand Down Expand Up @@ -43,11 +41,6 @@ def adapt_node(
)
for key, var in node.outputs.get_vars().items()
]
initializers = [
from_array(var._value, name) # type: ignore
for name, var in node.inputs.get_vars().items()
if isinstance(var._value, np.ndarray)
]
except ValueError:
return None

Expand All @@ -57,7 +50,6 @@ def adapt_node(
"spox__singleton_adapter_graph",
list(input_info.values()),
output_info,
initializers,
),
opset_imports=[onnx.helper.make_operatorsetid("", source_version)],
)
Expand Down
13 changes: 13 additions & 0 deletions tests/test_adapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from spox import Tensor, Var, argument, build, inline
from spox._attributes import AttrInt64s
from spox._fields import BaseAttributes, BaseInputs, BaseOutputs
from spox._future import initializer
from spox._graph import arguments, results
from spox._node import OpType
from spox._standard import StandardNode
Expand Down Expand Up @@ -157,6 +158,18 @@ def test_adapt_node_with_repeating_input_names():
build({"a": a}, {"b": b, "c": c})


def test_adapt_node_initializer():
init_data = [1.0, 2.0, 3.0]

a = argument(Tensor(np.float32, ("N",)))
b = initializer(init_data, np.float32)
c = op18.equal(a, b)
d = op19.identity(a)

model = build({"a": a}, {"b": b, "c": c, "d": d})
np.testing.assert_allclose(model.graph.initializer[0].float_data, init_data)


def test_inline_model_custom_node_only():
"""Inline a model which only consists of a custom node.
Expand Down

0 comments on commit ca7ebbe

Please sign in to comment.