class_docstr: This class should be used as a base for all DeepSpeed configs. It extends
  pydantic.BaseModel to allow for deprecated fields. To enable this feature,
  add deprecated=True to pydantic.Field:
  
  my_dep_field: int = Field(0, deprecated=True)
  
  Deprecated Field kwargs:
  - deprecated: [True|False], default False
      Enables / Disables deprecated fields
  - new_param: str, default ""
      Name of the field replacing the deprecated field
  - set_new_param: [True|False], default True
      If new_param is provided, enables setting the value of that param with
      deprecated field value
  - new_param_fn: callable, default (lambda x: x)
      If new_param is provided and set_new_param is True, this function will
      modify the value of the deprecated field before placing that value in
      the new_param field
  
  Example:
      my_new_field is replacing a deprecated my_old_field. The expected type
      for my_new_field is int while the expected type for my_old_field is
      str. We want to maintain backward compatibility with our configs, so we
      define the fields with:
  
      class MyExampleConfig(DeepSpeedConfigModel):
          my_new_field: int = 0
          my_old_field: str = Field('0',
                                    deprecated=True,
                                    new_param='my_new_field',
                                    new_param_fn=(lambda x: int(x)))
class_docstr_tok: ["This","class","should","be","used","as","a","base","for","all","DeepSpeed","configs",".","It","extends","pydantic.BaseModel","to","allow","for","deprecated","fields",".","To","enable","this","feature",",","add","deprecated=True","to","pydantic.Field",":","my_dep_field",":","int","=","Field","(","0",",","deprecated=True",")","Deprecated","Field","kwargs",":","-","deprecated",":","[","True|False","]",",","default","False","Enables","\/","Disables","deprecated","fields","-","new_param",":","str",",","default","``","''","Name","of","the","field","replacing","the","deprecated","field","-","set_new_param",":","[","True|False","]",",","default","True","If","new_param","is","provided",",","enables","setting","the","value","of","that","param","with","deprecated","field","value","-","new_param_fn",":","callable",",","default","(","lambda","x",":","x",")","If","new_param","is","provided","and","set_new_param","is","True",",","this","function","will","modify","the","value","of","the","deprecated","field","before","placing","that","value","in","the","new_param","field","Example",":","my_new_field","is","replacing","a","deprecated","my_old_field",".","The","expected","type","for","my_new_field","is","int","while","the","expected","type","for","my_old_field","is","str",".","We","want","to","maintain","backward","compatibility","with","our","configs",",","so","we","define","the","fields","with",":","class","MyExampleConfig","(","DeepSpeedConfigModel",")",":","my_new_field",":","int","=","0","my_old_field",":","str","=","Field","(","'","0","'",",","deprecated=True",",","new_param='my_new_field","'",",","new_param_fn=","(","lambda","x",":","int","(","x",")",")",")"]
code: def _process_deprecated_field(self, pydantic_config, field):
      # Get information about the deprecated field
      fields_set = pydantic_config.__fields_set__
      dep_param = field.name
      kwargs = field.field_info.extra
      new_param_fn = kwargs.get("new_param_fn", lambda x: x)
      param_value = new_param_fn(getattr(pydantic_config, dep_param))
      new_param = kwargs.get("new_param", "")
      if dep_param in fields_set:
          logger.warning(
              f"Config parameter {dep_param} is deprecated"
              + (f" use {new_param} instead" if new_param else "")
          )
          # Check if there is a new param and if it should be set with a value
          if new_param and kwargs.get("set_new_param", True):
              # Remove the deprecate field if there is a replacing field
              try:
                  delattr(pydantic_config, dep_param)
              except Exception as e:
                  logger.error(
                      f"Tried removing deprecated '{dep_param}' from config"
                  )
                  raise e
  
              # Set new param value
              new_param_nested = new_param.split(".")
              if len(new_param_nested) > 1:
                  # If the new param exists in a subconfig, we need to get
                  # the fields set for that subconfig
                  pydantic_config = reduce(
                      getattr, new_param_nested[:-1], pydantic_config
                  )
                  fields_set = pydantic_config.__fields_set__
              new_param_name = new_param_nested[-1]
              assert (
                  new_param_name not in fields_set
              ), f"Cannot provide deprecated parameter '{dep_param}' and replacing parameter '{new_param}' together"
              # A custom function for converting the old param value to new param value can be provided
              try:
                  setattr(pydantic_config, new_param_name, param_value)
              except Exception as e:
                  logger.error(
                      f"Tried setting value for '{new_param}' with value from deprecated '{dep_param}'"
                  )
                  raise e
  
imports: import json
  import collections
  import collections.abc
  from functools import reduce
  from pydantic import BaseModel
  from deepspeed.utils import logger
label_desc: Use image node_id 2 for calling the DeepSpeedConfigModel obj's underlying member method code with example usage: obj._process_deprecated_field(pydantic_config, field) without return types