You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
float16 constant readout doesn't match with it's original numpy array #53260
I tried to create float16 constant from numpy array and read it back, but the returned array doesn't match with it's original numpy array. This seems to be happening only at M1 Macs.
System information
OS Platform and Distribution (e.g., Linux Ubuntu 16.04): macOS 11.3.1 on M1 Mac mini
TensorFlow installed from (source or binary): Binary (tensorflow-macos)
TensorFlow version (use command below): unknown 2.5.0
It is working fine when checked with TF 2.7.0 on colab. Here's the gist. Since its not a bug from TF end and you also mentioned that the issue is with M1, Can you try posting your question in this tf-metal developer forum of Apple? Thanks!
@cfRod@everton1984 Have you seen similar issues before? Could you please help try this code on other Arm machines as well? I wonder if this is specific to M1.
@youchangkim Are these lines necessary in producing the error? (We don't have M1s so it's hard for us to test.)
x = np.random.sample([1, 1, 1, 1, 768]).astype(np.float16)
y = tf.constant(x)
@penpornk I was only able to try 2.7.0 since 2.8.0 requires macOS 12.3 but I'm currently using 11.3. I can try 2.8.0 after I upgrade my OS. Interestingly TF 2.5.0 and 2.7.0 produces different outputs but both are wrong.
Quick update:
Worked with @youchangkim offline and narrowed down to grappler optimization passes. It seems the GraphDef representation of the const all-one fp16 tensor was changed from
I0331 20:22:16.951792 1635096 convert_attributes.cc:287] GraphDef attr value: tensor {
dtype: DT_HALF
tensor_shape {
dim {
size: 1
}
dim {
size: 1
}
dim {
size: 384
}
dim {
size: 1
}
dim {
size: 1
}
}
half_val: 15360
}
to
I0331 20:22:16.951792 1635096 convert_attributes.cc:287] GraphDef attr value: tensor {
dtype: DT_HALF
tensor_shape {
dim {
size: 1
}
dim {
size: 1
}
dim {
size: 384
}
dim {
size: 1
}
dim {
size: 1
}
}
half_val: 1
}
@penpornk any update on this ?
the FP16 correctness issue seems to be affecting lot of TF core tests when run on Apple Silicon. They all pass on x86 machine like:
Activity
sanatmpa1 commentedon Dec 1, 2021
@youchangkim,
It is working fine when checked with TF
2.7.0on colab. Here's the gist. Since its not a bug from TF end and you also mentioned that the issue is with M1, Can you try posting your question in this tf-metal developer forum of Apple? Thanks!google-ml-butler commentedon Dec 13, 2021
This issue has been automatically marked as stale because it has no recent activity. It will be closed if no further activity occurs. Thank you.
google-ml-butler commentedon Dec 20, 2021
Closing as stale. Please reopen if you'd like to work on this further.
google-ml-butler commentedon Dec 20, 2021
Are you satisfied with the resolution of your issue?
Yes
No
penpornk commentedon Mar 8, 2022
@cfRod @everton1984 Have you seen similar issues before? Could you please help try this code on other Arm machines as well? I wonder if this is specific to M1.
@youchangkim Are these lines necessary in producing the error? (We don't have M1s so it's hard for us to test.)
Also, do you see the same error in eager mode?
6 remaining items
youchangkim commentedon Mar 10, 2022
@penpornk I was only able to try 2.7.0 since 2.8.0 requires macOS 12.3 but I'm currently using 11.3. I can try 2.8.0 after I upgrade my OS. Interestingly TF 2.5.0 and 2.7.0 produces different outputs but both are wrong.
TF 2.5.0
TF 2.7.0
Things you asked:
Fail both 2.5.0 and 2.7.0
Fail both 2.5.0 and 2.7.0
Fail both 2.5.0 and 2.7.0, and setting seed to 1 doesn't help
Applying 1, 2, and 3 at the same time also fails.
penpornk commentedon May 18, 2022
Quick update:
Worked with @youchangkim offline and narrowed down to grappler optimization passes. It seems the GraphDef representation of the const all-one fp16 tensor was changed from
to
after the tfg_optimizer pass.
mohantym commentedon Sep 12, 2022
@youchangkim ! @penpornk !
I could replicate this in my mac M1 machine . It is not replicating in Colab though.
kulinseth commentedon Oct 20, 2022
@penpornk any update on this ?
the FP16 correctness issue seems to be affecting lot of TF core tests when run on Apple Silicon. They all pass on x86 machine like:
Similarly for mlir to Graph def tests its failing:
This makes sense as the GraphDef representation changed for Half changed after tfg pass.
What I didn't follow is why its specific to arm64?
cc @yarri-oss , @nitins17 and @learning-to-play
penpornk commentedon Dec 12, 2022
@youchangkim @kulinseth Sorry for the delay! We have synced offline but I'll post the update here too.
This is where it went wrong:
tensorflow/tensorflow/core/ir/importexport/convert_tensor.cc
Line 348 in be3be93
MLIR's
getSplatValueis supposed to return 15360, but it returned 1.Here is a quick patch to work around this issue for now:
penpornk commentedon Dec 15, 2022
@cantonios just submitted a proper fix here: d4ea582.
Closing the issue now. Please feel free to reopen if it still isn't resolved on your side. :)
google-ml-butler commentedon Dec 15, 2022
Are you satisfied with the resolution of your issue?
Yes
No