@@ -312,6 +312,32 @@ def run_and_capture(model, input_dict):
312312 dim_size = edge_index .shape [1 ],
313313 ).cpu ()
314314
315+ linear = interaction .atom_mlp .linear
316+ linear_input = atom_attr .detach ()
317+ linear_weight = linear .weight .detach ()
318+ linear_bias = linear .bias .detach ()
319+ expected_linear = torch .nn .functional .linear (
320+ linear_input , linear_weight , linear_bias
321+ )
322+ mps_input = linear_input .to ("mps" )
323+ mps_weight = linear_weight .to ("mps" )
324+ mps_bias = linear_bias .to ("mps" )
325+
326+ def linear_max_abs (actual ):
327+ return float ((expected_linear - actual .cpu ()).abs ().max ())
328+
329+ primitive_diffs = {
330+ "weight_roundtrip" : float ((linear_weight - mps_weight .cpu ()).abs ().max ()),
331+ "functional_linear" : linear_max_abs (
332+ torch .nn .functional .linear (mps_input , mps_weight , mps_bias )
333+ ),
334+ "addmm" : linear_max_abs (torch .addmm (mps_bias , mps_input , mps_weight .T )),
335+ "matmul_plus_bias" : linear_max_abs (mps_input @ mps_weight .T + mps_bias ),
336+ "einsum_plus_bias" : linear_max_abs (
337+ torch .einsum ("bi,oi->bo" , mps_input , mps_weight ) + mps_bias
338+ ),
339+ }
340+
315341 stage_diffs = {
316342 name : float ((cpu_stages [name ] - mps_stages [name ]).abs ().max ())
317343 for name in targets
@@ -322,6 +348,8 @@ def run_and_capture(model, input_dict):
322348 "cpu_energy" : cpu_energy .tolist (),
323349 "mps_energy" : mps_energy .tolist (),
324350 "first_scatter_max_abs" : float ((cpu_scatter - mps_scatter ).abs ().max ()),
351+ "atom_mlp_linear_shape" : list (linear_input .shape ),
352+ "linear_primitive_max_abs" : primitive_diffs ,
325353 "stage_max_abs" : stage_diffs ,
326354 }
327355 pytest .fail (f"MPS stage diagnostic: { report } " )
0 commit comments