Summary
tf.constant(np_array) does not propagate the numpy array's dtype to the resulting tensor in Ariadne's inference. Any consumer of the resulting tensor sees ⊤ shape / UNKNOWN dtype.
Reproduction
Minimal fixture tf2_test_constant_from_numpy.py (on branch ml-22-empirical-top-p-logits, commit follows this issue):
import numpy as np
import tensorflow as tf
def consume(x):
return x
arr = tf.constant(np.ones((2, 3), dtype=np.float32))
consume(arr)
At runtime, arr.shape == (2, 3) and arr.dtype == tf.float32. Ariadne infers consume's parameter x as:
— both shape and dtype are ⊤, despite the explicit dtype=np.float32 on the numpy array and despite tf.constant preserving dtype faithfully at runtime.
Test: com.ibm.wala.cast.python.ml.test.TestTensorflow2Model.testConstantFromNumpy.
Impact
This pattern (tf.constant(np.ones / np.array / np.zeros(..., dtype=...))) is common in TF tutorial code and the perf-eval corpus. Surfaced during the input-signature-inference empirical pass (ponder-lab/Input-Signature-Inference-Paper#22) on YunYang1994/TensorFlow2.0-Examples/2-Basical_Models/Multilayer_Perceptron.py's multilayer_perceptron(x) function, which receives its parameter from a tf.constant(np.ones(...)) caller. With this bug, multilayer_perceptron(x) is the first load-bearing UNKNOWN-dtype function the empirical pass has identified — input-signature emission would fail because dtype is required.
This is a contributory blocker for input-signature inference on the perf-eval corpus.
Likely Cause
Ariadne's modeling of tf.constant (in tensorflow.xml) probably treats the argument as opaque rather than:
- Recognizing that the input is a numpy array.
- Reading the numpy array's
dtype attribute (or shape).
- Plumbing those into the resulting tensor's type.
The numpy-array → tensor type bridge needs first-class modeling.
Suggested Fix
Add a TensorGenerator (or extend an existing one for tf.constant) that:
- Detects when the value argument is a numpy ndarray construction (
np.ones(...), np.zeros(...), np.array(...)).
- Extracts the numpy
dtype keyword argument (or default).
- Maps to Ariadne's
DType enum.
- Extracts the shape argument from the numpy constructor for shape inference.
Related
Summary
tf.constant(np_array)does not propagate the numpy array's dtype to the resulting tensor in Ariadne's inference. Any consumer of the resulting tensor sees⊤ shape / UNKNOWN dtype.Reproduction
Minimal fixture
tf2_test_constant_from_numpy.py(on branchml-22-empirical-top-p-logits, commit follows this issue):At runtime,
arr.shape == (2, 3)andarr.dtype == tf.float32. Ariadne infersconsume's parameterxas:— both shape and dtype are ⊤, despite the explicit
dtype=np.float32on the numpy array and despitetf.constantpreserving dtype faithfully at runtime.Test:
com.ibm.wala.cast.python.ml.test.TestTensorflow2Model.testConstantFromNumpy.Impact
This pattern (
tf.constant(np.ones / np.array / np.zeros(..., dtype=...))) is common in TF tutorial code and the perf-eval corpus. Surfaced during the input-signature-inference empirical pass (ponder-lab/Input-Signature-Inference-Paper#22) onYunYang1994/TensorFlow2.0-Examples/2-Basical_Models/Multilayer_Perceptron.py'smultilayer_perceptron(x)function, which receives its parameter from atf.constant(np.ones(...))caller. With this bug,multilayer_perceptron(x)is the first load-bearing UNKNOWN-dtype function the empirical pass has identified — input-signature emission would fail because dtype is required.This is a contributory blocker for input-signature inference on the perf-eval corpus.
Likely Cause
Ariadne's modeling of
tf.constant(intensorflow.xml) probably treats the argument as opaque rather than:dtypeattribute (or shape).The numpy-array → tensor type bridge needs first-class modeling.
Suggested Fix
Add a
TensorGenerator(or extend an existing one fortf.constant) that:np.ones(...),np.zeros(...),np.array(...)).dtypekeyword argument (or default).DTypeenum.Related
TensorGeneratorsubclasses for #437/ReadDataFallbackops #449 —ReadDataFallback-routed ops;tf.constantandnp.ones/np.arraymay or may not be in scope (separate from this).