code: def make_and_consume_experience(strategy):
      EXPERIENCE_BATCH_SIZE = 4
      SAMPLE_BATCH_SIZE = 2
  
      if strategy == "ddp":
          strategy = DDPStrategy()
      elif strategy == "colossalai-zero2":
          strategy = LowLevelZeroStrategy()
      elif strategy == "colossalai-gemini":
          strategy = GeminiStrategy(placement_policy="static")
      else:
          raise ValueError(f'Unsupported strategy "{strategy}"')
  
      with strategy.model_init_context():
          actor = GPTActor(config=GPT_CONFIG).cuda()
          critic = GPTCritic(config=GPT_CONFIG).cuda()
  
          initial_model = GPTActor(config=GPT_CONFIG).cuda()
          reward_model = RewardModel(
              model=copy.deepcopy(critic.model)
          ).cuda()
  
      actor, critic, initial_model, reward_model = strategy.prepare(
          actor, critic, initial_model, reward_model
      )
  
      class MockTokenizer:
          def __init__(self):
              self.padding_side = "left"
              self.eos_token_id = 0
              self.pad_token_id = 0
  
      tokenizer = MockTokenizer()
      experience_maker = NaiveExperienceMaker(
          actor, critic, reward_model, initial_model, tokenizer
      )
      data_buffer = NaiveExperienceBuffer(
          SAMPLE_BATCH_SIZE, cpu_offload=False
      )
  
      generate_kwargs = dict(do_sample=True, max_length=16)
      generate_kwargs = _set_default_generate_kwargs(
          strategy, generate_kwargs, actor
      )
  
      # experience of all ranks should be the same
      for _ in range(2):
          data = get_data(EXPERIENCE_BATCH_SIZE)
          assert gather_and_equal(data["input_ids"])
          assert gather_and_equal(data["attention_mask"])
          experience = experience_maker.make_experience(
              **data, do_sample=True, max_length=16
          )
          assert gather_and_equal(experience.sequences)
          assert gather_and_equal(experience.action_log_probs)
          assert gather_and_equal(experience.values)
          assert gather_and_equal(experience.reward)
          assert gather_and_equal(experience.advantages)
          assert gather_and_equal(experience.action_mask)
          assert gather_and_equal(experience.attention_mask)
          data_buffer.append(experience)
  
      # data buffer's data should be the same
      buffer_size = torch.tensor([len(data_buffer)], device="cuda")
      assert gather_and_equal(buffer_size)
      for item in data_buffer.items:
          assert gather_and_equal(item.sequences)
          assert gather_and_equal(item.action_log_probs)
          assert gather_and_equal(item.values)
          assert gather_and_equal(item.reward)
          assert gather_and_equal(item.advantages)
          assert gather_and_equal(item.action_mask)
          assert gather_and_equal(item.attention_mask)
  
      # dataloader of each rank should have the same size and different batch
      dataloader = strategy.setup_dataloader(data_buffer)
      dataloader_size = torch.tensor([len(dataloader)], device="cuda")
      assert gather_and_equal(dataloader_size)
      for experience in dataloader:
          assert not gather_and_equal(experience.sequences)
          assert not gather_and_equal(experience.action_log_probs)
          assert not gather_and_equal(experience.values)
          assert not gather_and_equal(experience.reward)
          assert not gather_and_equal(experience.advantages)
  
file_path: ColossalAI/applications/Chat/tests/test_experience.py
imports: import copy
  import os
  import pytest
  import torch
  import torch.distributed
  from coati.experience_buffer import NaiveExperienceBuffer
  from coati.experience_maker import NaiveExperienceMaker
  from coati.models.base import RewardModel
  from coati.models.gpt import GPTActor, GPTCritic
  from coati.trainer.ppo import _set_default_generate_kwargs
  from coati.trainer.strategies import DDPStrategy, GeminiStrategy
  from coati.trainer.strategies.colossalai import LowLevelZeroStrategy
  from transformers.models.gpt2.configuration_gpt2 import GPT2Config
  from colossalai.testing import rerun_if_address_is_in_use, spawn
label_desc: Use image node_id 3 for calling a global function with example usage: make_and_consume_experience(strategy) without return types