MCPcopy Create free account
hub / github.com/BeastyZ/ConvSearch-R1 / test_data_transfer

Function test_data_transfer

verl/tests/ray/test_data_transfer.py:52–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

50
51
52def test_data_transfer():
53 ray.init()
54 # construct resource pool
55 resource_pool = RayResourcePool([8])
56 cls_with_init = RayClassWithInitArgs(cls=DummyWorker)
57 # construct worker group
58 wg = RayWorkerGroup(resource_pool, cls_with_init)
59
60 # this is real dataset size
61 batch_size = 4096
62 seqlen = 32768
63
64 data_dict = {}
65
66 for i in range(2):
67 data_dict[str(i)] = torch.randint(0, 10000, (batch_size, seqlen))
68
69 data = DataProto.from_dict(tensors=data_dict)
70
71 print(data)
72
73 # we manually split data here and send to each worker
74 data_list = data.chunk(wg.world_size)
75
76 for i in range(wg.world_size):
77 # consolidate is necessary
78 if tensordict.__version__ >= '0.5.0':
79 data_list[i].batch = data_list[i].batch.consolidate()
80
81 with Timer(name='ray.pickle', initial_text=True):
82 for i in range(wg.world_size):
83 ray.cloudpickle.pickle.dumps(data_list[i])
84
85 with Timer(name='raw.pickle', initial_text=True):
86 import pickle
87 for i in range(wg.world_size):
88 pickle.dumps(data_list[i])
89
90 # we put in advance
91 with Timer(name='put', initial_text=True):
92 # takes around 40 seconds
93 data_list_ref = parallel_put(data_list)
94 # for i in range(wg.world_size):
95 # data_list[i] = ray.put(data_list[i])
96
97 with Timer(name='launch', initial_text=True):
98 output_ref = wg.do_nothing(data_list_ref)
99
100 with Timer(name='get', initial_text=True):
101 # takes around 40 seconds
102 output_lst = ray.get(output_ref)
103
104 for input_data, output_data in zip(data_list, output_lst):
105 for key in input_data.batch.keys():
106 assert torch.all(torch.eq(input_data.batch[key] + 1,
107 output_data.batch[key])), (input_data.batch[key], output_data.batch[key], key)
108
109 ray.shutdown()

Callers

nothing calls this directly

Calls 9

RayResourcePoolClass · 0.90
RayWorkerGroupClass · 0.90
parallel_putFunction · 0.90
from_dictMethod · 0.80
do_nothingMethod · 0.80
initMethod · 0.45
chunkMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected