MCPcopy Create free account
hub / github.com/bitsandbytes-foundation/bitsandbytes / test_deepcopy_param

Function test_deepcopy_param

tests/test_linear4bit.py:287–309  ·  view source on GitHub ↗
(device, quant_type, blocksize, compress_statistics)

Source from the content-addressed store, hash-verified

285@pytest.mark.parametrize("blocksize", [32, 64, 128])
286@pytest.mark.parametrize("compress_statistics", TRUE_FALSE, ids=id_formatter("compress_statistics"))
287def test_deepcopy_param(device, quant_type, blocksize, compress_statistics):
288 if device == "hpu" and not is_supported_on_hpu(quant_type):
289 pytest.skip("This configuration is not supported on HPU.")
290
291 tensor = torch.randn(300, 400)
292 param = bnb.nn.Params4bit(
293 data=tensor,
294 quant_type=quant_type,
295 blocksize=blocksize,
296 compress_statistics=compress_statistics,
297 requires_grad=False,
298 ).to(device)
299 dict_keys_before = set(param.__dict__.keys())
300 copy_param = copy.deepcopy(param)
301 dict_keys_after = set(param.__dict__.keys())
302 dict_keys_copy = set(copy_param.__dict__.keys())
303
304 assert param.quant_state is not copy_param.quant_state
305 assert param.data.data_ptr() != copy_param.data.data_ptr()
306
307 # there was a bug where deepcopy would modify the original object
308 assert dict_keys_before == dict_keys_after
309 assert dict_keys_before == dict_keys_copy
310
311
312@pytest.mark.parametrize("device", get_available_devices())

Callers

nothing calls this directly

Calls 2

is_supported_on_hpuFunction · 0.90
toMethod · 0.45

Tested by

no test coverage detected