Repository navigation
Inference regression DML 1.10.1->1.11 and higher #483
Description
Activity
divideconcept commented
on Jul 15, 2023 AuthorMore actionsAfter further investigation, I've identified the node where values are misscalculated.
Opening model3.onnx in netron.app, around the end of the model there's a Transpose node:

This Transpose node has the following properties :
perm: 1,0,2
And that's where the results from CPU/DirectML 1.10.1 (or earlier) inference and DirectML 1.11 (or later) inference differ.Here's the code to repro (this requires the onnx package to be installed - also make sure DirectML.dll 1.11 or 1.12 is active):
# add all nodes of the model as outputs session = ort.InferenceSession("model3.onnx") outputs = [x.name for x in ort_session.get_outputs()] model = onnx.load("model3.onnx") for node in model.graph.node: for output in node.output: if output not in outputs: model.graph.output.extend([onnx.ValueInfoProto(name=output)]) # prepare inputs input0=np.ones((1,1,257,200),dtype=np.float32) input1=np.ones((1,1,257,200),dtype=np.float32) input2=np.ones((1,1,257,200),dtype=np.float32) # infere with CPU session = ort.InferenceSession(model.SerializeToString(), providers=['CPUExecutionProvider']) outputs=session.run(["1603"], {"noisy_mag.1": input0, "noisy_real.1": input1, "noisy_imag.1": input2}) print(outputs[0].shape, outputs[0]) # infere with DML session = ort.InferenceSession(model.SerializeToString(), providers=['DmlExecutionProvider']) outputs=session.run(["1603"], {"noisy_mag.1": input0, "noisy_real.1": input1, "noisy_imag.1": input2}) print(outputs[0].shape, outputs[0])Output from CPU:
(257, 202, 384) [[[-2.24244222e-02 -1.81161650e-02 1.04738630e-01 ... -2.62294384e-03 -5.24457321e-02 -8.63133818e-02] [ 4.34092991e-02 -1.91172038e-03 1.83144584e-01 ... -1.39332749e-02 -2.91350372e-02 -9.12476424e-03] [ 1.75927863e-01 -3.56033891e-02 7.00066835e-02 ... -4.62932549e-02 -2.47223936e-02 1.75747147e-03] ... [-6.26550429e-03 -5.27066961e-02 7.54785836e-02 ... -1.69345154e-03 -2.18201317e-02 5.16798394e-03] [ 9.01989988e-05 -1.04649691e-03 -3.37222181e-02 ... -1.02277445e-04 -1.39540777e-01 3.56663688e-04] [ 1.04166304e-06 7.25851278e-04 -4.34977338e-02 ... -1.32037560e-03 -1.24461785e-01 -2.93780504e-05]] [[-2.19303407e-02 -2.03029327e-02 8.90306607e-02 ... -2.52002873e-03 -5.03902100e-02 -9.85104367e-02] [ 4.52997573e-02 -4.39030398e-03 1.53681174e-01 ... -3.83538716e-02 -3.50315198e-02 -4.82412241e-03] [ 1.83614999e-01 -4.65713479e-02 5.76112531e-02 ... -2.95043159e-02 -2.42901165e-02 2.83370763e-02] ... [-1.99852079e-01 2.50023929e-03 6.05125464e-02 ... -7.08830729e-03 -2.81588733e-02 -3.04497313e-03] [ 3.59401945e-03 1.02978829e-05 -4.89478633e-02 ... -1.61632473e-04 -1.64531782e-01 1.38141841e-05] [ 2.19431549e-05 9.33293253e-03 -5.97366728e-02 ... -3.52595677e-03 -1.37281522e-01 -3.99660552e-03]] [[-2.07985602e-02 -1.83043443e-02 7.67841786e-02 ... -2.12177704e-03 -5.34841903e-02 -1.09880999e-01] [ 6.78566024e-02 -6.06867205e-03 1.08080104e-01 ... -6.17316738e-02 -3.18331569e-02 6.95146620e-03] [ 1.86760351e-01 -4.21980396e-02 3.38125788e-02 ... -3.79635952e-02 -2.70707775e-02 2.43895222e-02] ... [-7.53476471e-02 -8.28410790e-04 2.53375527e-02 ... -1.54487870e-03 -2.48027314e-02 -5.08362474e-03] [ 4.07979684e-03 2.41013331e-05 -4.57204618e-02 ... -1.08828162e-05 -1.78377748e-01 -2.01429557e-05] [ 2.72689631e-05 1.45370024e-03 -1.13494202e-01 ... 6.66758139e-03 -1.26200467e-01 -1.68970018e-03]] ... [[-3.46809463e-03 -5.06885955e-03 5.44518270e-02 ... -2.32961698e-04 -3.23662795e-02 -4.65176739e-02] [ 1.25713602e-01 -7.99832924e-04 6.82542399e-02 ... -1.07500739e-02 -3.50132622e-02 -4.65782505e-04] [ 5.00956237e-01 -3.48149613e-02 8.15351084e-02 ... -8.87240767e-02 -3.10592409e-02 -2.77274661e-03] ... [-2.32463349e-02 8.44998285e-05 1.38259038e-01 ... -2.73333775e-04 -2.28560623e-02 -1.55033249e-05] -1.23722441e-01 -2.60449979e-05]] [[-3.60833388e-03 -3.31441197e-03 3.89608592e-02 ... -2.54207203e-04 -2.99281497e-02 -4.30685245e-02] [ 1.27522528e-01 -6.38367143e-04 4.20251973e-02 ... -1.07803959e-02 -3.88976373e-02 -4.55969333e-04] [ 4.80060756e-01 -3.22379060e-02 6.08608425e-02 ... -8.77213329e-02 -3.32298428e-02 -2.54026917e-03] ... [ 1.57818496e-01 -5.59169974e-04 1.00797571e-01 ... 8.11835518e-04 -1.58398803e-02 1.24038830e-02] [ 1.41852035e-03 -4.16653165e-06 -2.36224048e-02 ... 9.30286405e-05 -8.67753774e-02 2.50721257e-03] [ 1.24601347e-05 2.43027398e-06 6.66262060e-02 ... 3.42243846e-04 -1.85495743e-03 -2.45646333e-05]] [[ 1.05812935e-04 1.44522940e-03 5.93114123e-02 ... -3.53662654e-06 -3.12188845e-02 -1.85762458e-02] [ 5.15261769e-01 2.65544280e-03 5.88782430e-02 ... -2.02777869e-06 6.93067670e-01 -2.88051833e-05] [ 8.76773731e-04 2.29678684e-04 2.79930890e-01 ... 1.00064881e-06 1.59177646e-01 -7.48374872e-03] ... [-4.68075825e-07 8.12394774e-06 1.00143395e-01 ... 5.46613244e-08 9.41725254e-01 -4.87099271e-07] [ 9.36946366e-04 2.75643231e-07 2.74980843e-01 ... 8.97245727e-08 9.84934926e-01 1.19077333e-06] [-5.14064450e-04 1.32889836e-05 1.29662991e-01 ... 4.32575931e-08 9.92943466e-01 4.11752978e-08]]]Output from DirectML:
(257, 202, 384) [[[-2.24237777e-02 -1.81159042e-02 1.04737826e-01 ... -2.62334966e-03 -5.24464287e-02 -8.63163546e-02] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] ... [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00]] [[-2.19296645e-02 -2.03028359e-02 8.90300572e-02 ... -2.52034538e-03 -5.03907092e-02 -9.85143781e-02] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] ... [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00]] [[-2.07979754e-02 -1.83043629e-02 7.67838955e-02 ... -2.12199963e-03 -5.34842797e-02 -1.09886073e-01] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] ... [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00]] ... [[-3.46806739e-03 -5.06879063e-03 5.44530377e-02 ... -2.32965860e-04 -3.23669985e-02 -4.65166308e-02] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] ... [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00]] [[-3.60834715e-03 -3.31466878e-03 3.89620177e-02 ... -2.54210085e-04 -2.99288891e-02 -4.30673063e-02] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] ... [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00]] [[ 1.06376880e-04 1.44572917e-03 5.93050644e-02 ... -3.53716496e-06 -3.12189274e-02 -1.85762532e-02] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] ... [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00] [ 0.00000000e+00 0.00000000e+00 0.00000000e+00 ... 0.00000000e+00 0.00000000e+00 0.00000000e+00]]]If you check the input of this Transpose (node 1602), both CPU and DirectML values match.
So for some reason the Transpose with
perm 1,0,2doesn't work with DirectML 1.11 and higher. The output shape is correct, but the values are all messed up.- changed the title
[-]Inference regression DML 10.1->11 and higher[/-][+]Inference regression DML 1.10.1->1.11 and higher[/+]on Jul 16, 2023 divideconcept commented
on Jul 18, 2023 AuthorMore actionsjstoecker commented
on Jul 19, 2023 ContributorMore actionsThanks for reporting this, we'll try to take a look soon. Brian Martin (@martinb35)
Reacted by Dwayne RobinsonSheil Kumar (@smk2007) has a pending fix for an upcoming patch release in a few weeks. ⏳
Reacted by Robin LobelRobin Lobel (@divideconcept) this issue has been fixed in DirectML 1.12.1. This fix will also be incorporated into the upcoming onnxruntime-directml 1.16 which is expected to release in the coming weeks.
Reacted by Robin Lobel and Dwayne RobinsonRobin Lobel (@divideconcept) I'm curious if DirectML.dll 1.12.1 solved it? (appears the ORT 1.16 release is still delayed...)
divideconcept commented
on Sep 18, 2023 AuthorMore actionsDwayne Robinson (@fdwr) Adrian Tsai (@adtsai) I confirm DirectML 1.12.1 fixed the issue !
Reacted by Dwayne RobinsonThanks Sheil for fixing and Robin for verifying. Closing ✅.
I noticed an inference regression between DML 1.10.1 (and earlier) and DML 1.11 (and later), which causes the inference results to be completely off with some models. I'm not sure what node exactly cause the issue, but here's a complete repro step by step:
pip install onnxruntime-directml.This will show the following output:
In practice, those values are the expected output.
This will show the following output:
Notice the results are completely different (and in practice, no useable value is produced)
Lib\site-packages\onnxruntime\capiand rename DirectML.dll to DirectML.bak.This will show the following output:
Notice the results are very close, almost identicals to the CPU output. And in practice the values correspond to what is expected.
With this model, correct values are produced with DirectML 1.8, 1.9, 1.10, 1.10.1, and bad values are produced with DirectML 1.11, 1.12. Note that the final tensor shape is correct, only the values are wrong.
My DirectML device is a GeForce RTX 3090.