@@ -296,6 +296,47 @@ def test_compute_layer_means(n_balance_layers, group_size, n_input_features):
296296 assert_close (auto_awq_means , llmc_awq_means )
297297
298298
299+ @pytest .mark .unit
300+ @torch .no_grad
301+ def test_compute_layer_means_does_not_modify_weights ():
302+ """
303+ Test that _compute_layer_means does not modify the original layer weights.
304+ This is a regression test for a bug where in-place operations (abs_, div_)
305+ were modifying the original weights.
306+ """
307+ # Create test layers with known weight values
308+ n_layers = 3
309+ n_input_features = 16
310+ layers = [torch .nn .Linear (n_input_features , 8 ) for _ in range (n_layers )]
311+
312+ # Set up quantization scheme for channel-wise quantization
313+ for layer in layers :
314+ setattr (
315+ layer ,
316+ "quantization_scheme" ,
317+ QuantizationScheme (
318+ targets = ["Linear" ],
319+ weights = QuantizationArgs (
320+ strategy = QuantizationStrategy .CHANNEL ,
321+ ),
322+ ),
323+ )
324+
325+ # Store copies of original weights before calling _compute_layer_means
326+ original_weights = [layer .weight .clone () for layer in layers ]
327+
328+ # Call _compute_layer_means which should NOT modify the original weights
329+ AWQModifier ._compute_layer_means (layers )
330+
331+ # Verify that the original weights remain unchanged
332+ for i , layer in enumerate (layers ):
333+ assert_close (
334+ layer .weight ,
335+ original_weights [i ],
336+ msg = f"Layer { i } weight was modified by _compute_layer_means" ,
337+ )
338+
339+
299340@pytest .mark .unit
300341@pytest .mark .parametrize (
301342 "rows, cols, block_height, block_width" ,
0 commit comments