code: def trim_encoded_sagemaker_parameters(
      encoded_params: dict, max_len: int = 256
  ) -> dict:
      """
      Trim parameters that have already been encoded to a given max length.
  
      Example:
  
      >>> trim_encoded_sagemaker_parameters({
      ...     'foo': '[1, 2, 3]',
      ...     'bar': 'hello'
      ... }, max_len = 4)
      {'_0_foo': '[1, ',
       '_1_foo': '2, 3',
       '_2_foo': ']',
       '_0_bar': 'hell',
       '_1_bar': 'o'}
      """
      trimmed_params = {}
      for key, value in encoded_params.items():
          if len(value) > max_len:
              for idx, substr in enumerate(batcher(value, max_len)):
                  trimmed_params[f"_{idx}_{key}"] = "".join(substr)
          else:
              trimmed_params[key] = value
      return trimmed_params
  
file_path: gluonts/src/gluonts/shell/sagemaker/params.py
imports: from itertools import count
  from typing import Any, Union
  from toolz import valmap
  from gluonts.core.serde import dump_json, load_json
  from gluonts.itertools import batcher
label_desc: Use image node_id 7 for calling a global function with example usage: trim_encoded_sagemaker_parameters(encoded_params, max_len) and returns: trimmed_params