code: def _add_train_general_opts(parser):
      """General options for training"""
      group = parser.add_argument_group("General")
      group.add(
          "--data_type",
          "-data_type",
          default="text",
          help="Type of the source input. " "Options are [text].",
      )
  
      group.add(
          "-bucket_size",
          "--bucket_size",
          type=int,
          default=262144,
          help="""A bucket is a buffer of bucket_size examples to pick
                     from the various Corpora. The dynamic iterator batches
                     batch_size batchs from the bucket and shuffle them.""",
      )
      group.add(
          "-bucket_size_init",
          "--bucket_size_init",
          type=int,
          default=-1,
          help="""The bucket is initalized with this awith this
                 amount of examples (optional)""",
      )
      group.add(
          "-bucket_size_increment",
          "--bucket_size_increment",
          type=int,
          default=0,
          help="""The bucket size is incremented with this
                amount of examples (optional)""",
      )
      group.add(
          "-prefetch_factor",
          "--prefetch_factor",
          type=int,
          default=200,
          help="""number of mini-batches loaded in advance to avoid the
                     GPU waiting during the refilling of the bucket.""",
      )
      group.add(
          "--save_model",
          "-save_model",
          default="model",
          help="Model filename (the model will be saved as "
          "<save_model>_N.pt where N is the number "
          "of steps",
      )
  
      group.add(
          "--save_format",
          "-save_format",
          default="pytorch",
          choices=["pytorch", "safetensors"],
          help="Format to save the model weights",
      )
  
      group.add(
          "--save_checkpoint_steps",
          "-save_checkpoint_steps",
          type=int,
          default=5000,
          help="""Save a checkpoint every X steps""",
      )
      group.add(
          "--keep_checkpoint",
          "-keep_checkpoint",
          type=int,
          default=-1,
          help="Keep X checkpoints (negative: keep all)",
      )
  
      # LoRa
      group.add(
          "--lora_layers",
          "-lora_layers",
          default=[],
          nargs="+",
          type=str,
          help="list of layers to be replaced by LoRa layers."
          " ex: ['linear_values', 'linear_query'] "
          " cf paper §4.2 https://arxiv.org/abs/2106.09685",
      )
      group.add(
          "--lora_embedding",
          "-lora_embedding",
          action="store_true",
          help="replace embeddings with LoRa Embeddings see §5.1",
      )
      group.add(
          "--lora_rank",
          "-lora_rank",
          type=int,
          default=2,
          help="r=2 successfully tested with NLLB-200 3.3B",
      )
      group.add(
          "--lora_alpha",
          "-lora_alpha",
          type=int,
          default=1,
          help="§4.1 https://arxiv.org/abs/2106.09685",
      )
      group.add(
          "--lora_dropout",
          "-lora_dropout",
          type=float,
          default=0.0,
          help="rule of thumb: same value as in main model",
      )
  
      _add_reproducibility_opts(parser)
  
      # Init options
      group = parser.add_argument_group("Initialization")
      group.add(
          "--param_init",
          "-param_init",
          type=float,
          default=0.1,
          help="Parameters are initialized over uniform distribution "
          "with support (-param_init, param_init). "
          "Use 0 to not use initialization",
      )
      group.add(
          "--param_init_glorot",
          "-param_init_glorot",
          action="store_true",
          help="Init parameters with xavier_uniform. "
          "Required for transformer.",
      )
  
      group.add(
          "--train_from",
          "-train_from",
          default="",
          type=str,
          help="If training from a checkpoint then this is the "
          "path to the pretrained model's state_dict.",
      )
      group.add(
          "--reset_optim",
          "-reset_optim",
          default="none",
          choices=["none", "all", "states", "keep_states"],
          help="Optimization resetter when train_from.",
      )
  
      # Pretrained word vectors
      group.add(
          "--pre_word_vecs_enc",
          "-pre_word_vecs_enc",
          help="If a valid path is specified, then this will load "
          "pretrained word embeddings on the encoder side. "
          "See README for specific formatting instructions.",
      )
      group.add(
          "--pre_word_vecs_dec",
          "-pre_word_vecs_dec",
          help="If a valid path is specified, then this will load "
          "pretrained word embeddings on the decoder side. "
          "See README for specific formatting instructions.",
      )
      # Freeze word vectors
      group.add(
          "--freeze_word_vecs_enc",
          "-freeze_word_vecs_enc",
          action="store_true",
          help="Freeze word embeddings on the encoder side.",
      )
      group.add(
          "--freeze_word_vecs_dec",
          "-freeze_word_vecs_dec",
          action="store_true",
          help="Freeze word embeddings on the decoder side.",
      )
  
      # Optimization options
      group = parser.add_argument_group("Optimization- Type")
      group.add(
          "--num_workers",
          "-num_workers",
          type=int,
          default=2,
          help="pytorch DataLoader num_workers",
      )
      group.add(
          "--batch_size",
          "-batch_size",
          type=int,
          default=64,
          help="Maximum batch size for training",
      )
      group.add(
          "--batch_size_multiple",
          "-batch_size_multiple",
          type=int,
          default=1,
          help="Batch size multiple for token batches.",
      )
      group.add(
          "--batch_type",
          "-batch_type",
          default="sents",
          choices=["sents", "tokens"],
          help="Batch grouping for batch_size. Standard "
          "is sents. Tokens will do dynamic batching",
      )
      group.add(
          "--normalization",
          "-normalization",
          default="sents",
          choices=["sents", "tokens"],
          help="Normalization method of the gradient.",
      )
      group.add(
          "--accum_count",
          "-accum_count",
          type=int,
          nargs="+",
          default=[1],
          help="Accumulate gradient this many times. "
          "Approximately equivalent to updating "
          "batch_size * accum_count batches at once. "
          "Recommended for Transformer.",
      )
      group.add(
          "--accum_steps",
          "-accum_steps",
          type=int,
          nargs="+",
          default=[0],
          help="Steps at which accum_count values change",
      )
      group.add(
          "--valid_steps",
          "-valid_steps",
          type=int,
          default=10000,
          help="Perfom validation every X steps",
      )
      group.add(
          "--valid_batch_size",
          "-valid_batch_size",
          type=int,
          default=32,
          help="Maximum batch size for validation",
      )
      group.add(
          "--train_steps",
          "-train_steps",
          type=int,
          default=100000,
          help="Number of training steps",
      )
      group.add(
          "--single_pass",
          "-single_pass",
          action="store_true",
          help="Make a single pass over the training dataset.",
      )
      group.add(
          "--early_stopping",
          "-early_stopping",
          type=int,
          default=0,
          help="Number of validation steps without improving.",
      )
      group.add(
          "--early_stopping_criteria",
          "-early_stopping_criteria",
          nargs="*",
          default=None,
          help="Criteria to use for early stopping.",
      )
      group.add(
          "--optim",
          "-optim",
          default="sgd",
          choices=[
              "sgd",
              "adagrad",
              "adadelta",
              "adam",
              "sparseadam",
              "adafactor",
              "fusedadam",
              "adamw8bit",
              "pagedadamw8bit",
              "pagedadamw32bit",
          ],
          help="Optimization method.",
      )
      group.add(
          "--adagrad_accumulator_init",
          "-adagrad_accumulator_init",
          type=float,
          default=0,
          help="Initializes the accumulator values in adagrad. "
          "Mirrors the initial_accumulator_value option "
          "in the tensorflow adagrad (use 0.1 for their default).",
      )
      group.add(
          "--max_grad_norm",
          "-max_grad_norm",
          type=float,
          default=5,
          help="If the norm of the gradient vector exceeds this, "
          "renormalize it to have the norm equal to "
          "max_grad_norm",
      )
      group.add(
          "--dropout",
          "-dropout",
          type=float,
          default=[0.3],
          nargs="+",
          help="Dropout probability; applied in LSTM stacks.",
      )
      group.add(
          "--attention_dropout",
          "-attention_dropout",
          type=float,
          default=[0.1],
          nargs="+",
          help="Attention Dropout probability.",
      )
      group.add(
          "--dropout_steps",
          "-dropout_steps",
          type=int,
          nargs="+",
          default=[0],
          help="Steps at which dropout changes.",
      )
      group.add(
          "--truncated_decoder",
          "-truncated_decoder",
          type=int,
          default=0,
          help="""Truncated bptt.""",
      )
      group.add(
          "--adam_beta1",
          "-adam_beta1",
          type=float,
          default=0.9,
          help="The beta1 parameter used by Adam. "
          "Almost without exception a value of 0.9 is used in "
          "the literature, seemingly giving good results, "
          "so we would discourage changing this value from "
          "the default without due consideration.",
      )
      group.add(
          "--adam_beta2",
          "-adam_beta2",
          type=float,
          default=0.999,
          help="The beta2 parameter used by Adam. "
          "Typically a value of 0.999 is recommended, as this is "
          "the value suggested by the original paper describing "
          "Adam, and is also the value adopted in other frameworks "
          "such as Tensorflow and Keras, i.e. see: "
          "https://www.tensorflow.org/api_docs/python/tf/train/Adam"
          "Optimizer or https://keras.io/optimizers/ . "
          'Whereas recently the paper "Attention is All You Need" '
          "suggested a value of 0.98 for beta2, this parameter may "
          "not work well for normal models / default "
          "baselines.",
      )
      group.add(
          "--label_smoothing",
          "-label_smoothing",
          type=float,
          default=0.0,
          help="Label smoothing value epsilon. "
          "Probabilities of all non-true labels "
          "will be smoothed by epsilon / (vocab_size - 1). "
          "Set to zero to turn off label smoothing. "
          "For more detailed information, see: "
          "https://arxiv.org/abs/1512.00567",
      )
      group.add(
          "--average_decay",
          "-average_decay",
          type=float,
          default=0,
          help="Moving average decay. "
          "Set to other than 0 (e.g. 1e-4) to activate. "
          "Similar to Marian NMT implementation: "
          "http://www.aclweb.org/anthology/P18-4020 "
          "For more detail on Exponential Moving Average: "
          "https://en.wikipedia.org/wiki/Moving_average",
      )
      group.add(
          "--average_every",
          "-average_every",
          type=int,
          default=1,
          help="Step for moving average. "
          "Default is every update, "
          "if -average_decay is set.",
      )
  
      # learning rate
      group = parser.add_argument_group("Optimization- Rate")
      group.add(
          "--learning_rate",
          "-learning_rate",
          type=float,
          default=1.0,
          help="Starting learning rate. "
          "Recommended settings: sgd = 1, adagrad = 0.1, "
          "adadelta = 1, adam = 0.001",
      )
      group.add(
          "--learning_rate_decay",
          "-learning_rate_decay",
          type=float,
          default=0.5,
          help="If update_learning_rate, decay learning rate by "
          "this much if steps have gone past "
          "start_decay_steps",
      )
      group.add(
          "--start_decay_steps",
          "-start_decay_steps",
          type=int,
          default=50000,
          help="Start decaying every decay_steps after "
          "start_decay_steps",
      )
      group.add(
          "--decay_steps",
          "-decay_steps",
          type=int,
          default=10000,
          help="Decay every decay_steps",
      )
  
      group.add(
          "--decay_method",
          "-decay_method",
          type=str,
          default="none",
          choices=["noam", "noamwd", "rsqrt", "none"],
          help="Use a custom decay rate.",
      )
      group.add(
          "--warmup_steps",
          "-warmup_steps",
          type=int,
          default=4000,
          help="Number of warmup steps for custom decay.",
      )
      _add_logging_opts(parser, is_train=True)
  
imports: import configargparse
  from onmt.modules.sru import CheckSRU
  from onmt.transforms import AVAILABLE_TRANSFORMS
  from onmt.constants import ModelTask
  from onmt.modules.position_ffn import ACTIVATION_FUNCTIONS
  from onmt.modules.position_ffn import ActivationFunction
  from onmt.constants import DefaultTokens
label_desc: Use image node_id 11 for calling a global function with example usage: _add_train_general_opts(parser) without return types