MCPcopy
hub / github.com/deepspeedai/DeepSpeed / test_offset_read

Method test_offset_read

tests/unit/ops/aio/test_gds.py:329–357  ·  view source on GitHub ↗
(self, tmpdir, file_partitions)

Source from the content-addressed store, hash-verified

327 h.unpin_device_tensor(gds_buffer)
328
329 def test_offset_read(self, tmpdir, file_partitions):
330 partition_unit_size = BLOCK_SIZE
331 file_size = sum(file_partitions) * partition_unit_size
332 ref_file, _ = _do_ref_write(tmpdir, 0, file_size)
333 h = GDSBuilder().load().gds_handle(BLOCK_SIZE, QUEUE_DEPTH, True, True, IO_PARALLEL)
334
335 gds_buffer = torch.empty(file_size, dtype=torch.uint8, device=get_accelerator().device_name())
336 h.pin_device_tensor(gds_buffer)
337
338 file_offsets = []
339 next_offset = 0
340 for i in range(len(file_partitions)):
341 file_offsets.append(next_offset)
342 next_offset += file_partitions[i] * partition_unit_size
343
344 with open(ref_file, 'rb') as ref_fd:
345 for i in range(len(file_partitions)):
346 ref_fd.seek(file_offsets[i])
347 bytes_to_read = file_partitions[i] * partition_unit_size
348 ref_buf = list(ref_fd.read(bytes_to_read))
349
350 dst_tensor = torch.narrow(gds_buffer, 0, 0, bytes_to_read)
351 read_status = h.async_pread(dst_tensor, ref_file, file_offsets[i])
352 assert read_status == 0
353 wait_status = h.wait()
354 assert wait_status == 1
355 assert dst_tensor.tolist() == ref_buf
356
357 h.unpin_device_tensor(gds_buffer)

Callers

nothing calls this directly

Calls 8

GDSBuilderClass · 0.90
get_acceleratorFunction · 0.90
appendMethod · 0.80
_do_ref_writeFunction · 0.70
loadMethod · 0.45
device_nameMethod · 0.45
readMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected