MCPcopy Create free account
hub / github.com/InternLM/InternBootcamp / test_critic_engine

Function test_critic_engine

verl/tests/models/test_engine.py:250–350  ·  view source on GitHub ↗
(strategy)

Source from the content-addressed store, hash-verified

248
249@pytest.mark.parametrize("strategy", ["fsdp", "fsdp2"])
250def test_critic_engine(strategy):
251 device_count = torch.cuda.device_count()
252 value_model_path = os.path.expanduser("~/models/test_model")
253 language_model_path = get_test_language_model(device_count=device_count)
254 create_value_model(language_model_path, value_model_path)
255
256 torch.manual_seed(1)
257 np.random.seed(1)
258
259 ray.init()
260
261 config = create_training_config(
262 model_type="value_model", strategy=strategy, device_count=device_count, model=value_model_path
263 )
264 ray_cls_with_init = RayClassWithInitArgs(cls=ray.remote(TrainingWorker), config=config)
265 resource_pool = RayResourcePool(process_on_nodes=[device_count])
266 wg = RayWorkerGroup(resource_pool=resource_pool, ray_cls_with_init=ray_cls_with_init)
267 # init model
268 wg.reset()
269
270 batch_size = 8
271 seqlen = 32
272
273 response_length = seqlen // 2
274 input_ids = torch.randint(0, config.model_config.hf_config.vocab_size, (batch_size, seqlen))
275 attention_mask = create_random_mask(
276 input_ids=input_ids, max_ratio_of_valid_token=0.8, max_ratio_of_left_padding=0.2, min_ratio_of_valid_token=0.6
277 )
278 position_ids = compute_position_id_with_mask(attention_mask)
279
280 global_token_num = torch.sum(attention_mask, dim=-1).tolist()
281
282 print(input_ids.float().mean(), attention_mask.float().mean())
283
284 responses = input_ids[:, response_length:]
285 response_mask = attention_mask[:, response_length:]
286
287 assert torch.all(response_mask[:, 0] == 1)
288
289 data = DataProto.from_single_dict(
290 {
291 "input_ids": input_ids,
292 "prompts": input_ids[:, :response_length],
293 "attention_mask": attention_mask,
294 "position_ids": position_ids,
295 "responses": responses,
296 "response_mask": response_mask,
297 },
298 meta_info={"temperature": 1.0, "global_token_num": global_token_num, "compute_loss": False},
299 )
300
301 data_td = data.to_tensordict()
302 data_td = left_right_2_no_padding(data_td)
303
304 # eval
305 output = wg.infer_batch(data_td)
306 output = output.get()
307

Callers

nothing calls this directly

Calls 15

RayResourcePoolClass · 0.90
RayWorkerGroupClass · 0.90
create_random_maskFunction · 0.90
left_right_2_no_paddingFunction · 0.90
no_padding_2_paddingFunction · 0.90
CriticConfigClass · 0.90
get_test_language_modelFunction · 0.85
create_value_modelFunction · 0.85
create_training_configFunction · 0.85
to_tensordictMethod · 0.80

Tested by

no test coverage detected