code: def _build_generic_gpt_pipeline_1d(
      module_cls,
      num_layers,
      num_chunks,
      device=torch.device("cuda"),
      **kwargs,
  ):
      logger = get_dist_logger()
  
      if gpc.is_initialized(ParallelMode.PIPELINE):
          pipeline_size = gpc.get_world_size(ParallelMode.PIPELINE)
          pipeline_rank = gpc.get_local_rank(ParallelMode.PIPELINE)
      else:
          pipeline_size = 1
          pipeline_rank = 0
      rank = gpc.get_global_rank()
  
      if pipeline_size > 1:
          wrapper = PipelineSharedModuleWrapper([0, pipeline_size - 1])
      else:
          wrapper = None
      parts = partition_uniform(num_layers, pipeline_size, num_chunks)[
          pipeline_rank
      ]
      models = []
      for start, end in parts:
          kwargs["num_layers"] = end - start
          kwargs["first"] = start == 0
          kwargs["last"] = end == num_layers
          logger.info(
              f"Rank{rank} build layer {start}-{end}, {end-start}/{num_layers} layers"
          )
          chunk = module_cls(
              **_filter_kwargs(module_cls.__init__, kwargs)
          ).to(device)
  
          if wrapper is not None:
              if start == 0:
                  wrapper.register_module(
                      chunk.embedding.word_embeddings
                  )
              elif end == num_layers:
                  wrapper.register_module(chunk.head)
          models.append(chunk)
      if len(models) == 1:
          model = models[0]
      else:
          model = nn.ModuleList(models)
  
      numel = 0
      for _, param in model.named_parameters(recurse=True):
          numel += param.numel()
      logger.info(
          f"Rank{rank}/{pipeline_rank} model size = {numel * 2 / 1e9} GB"
      )
      return model
  
imports: import inspect
  import titans.model.gpt.gpt
  import torch
  import torch.nn
  from colossalai import kernel
  from colossalai import nn
  from colossalai.legacy.context.parallel_mode import ParallelMode
  from colossalai.legacy.core import global_context
  from colossalai.legacy.nn.layer.wrapper import PipelineSharedModuleWrapper
  from colossalai.legacy.pipeline.utils import partition_uniform
  from colossalai.logging import get_dist_logger
  from .embed import HiddenParallelEmbedding, HiddenParallelGPTLMHead1D, VocabParallelEmbedding, VocabParallelGPTLMHead1D
  from .gpt1d import FusedGPTTransformerLayer1D, GPTTransformerLayer1D
label_desc: Use image node_id 2 for calling a global function with example usage: _build_generic_gpt_pipeline_1d(module_cls, num_layers, num_chunks, device) and returns: model