code: def write_external_data_tensors(
      model: ModelProto, filepath: str
  ) -> ModelProto:
      """
      Serializes data for all the tensors which have data location set to TensorProto.External.
  
      Note: This function also strips basepath information from all tensors' external_data fields.
  
      Arguments:
          model (ModelProto): Model object which is the source of tensors to serialize.
          filepath: System path to the directory which should be treated as base path for external data.
  
      Returns:
          ModelProto: The modified model object.
      """
      for tensor in _get_all_tensors(model):
          # Writing to external data happens in 2 passes:
          # 1. Tensors with raw data which pass the necessary conditions (size threshold etc) are marked for serialization
          # 2. The raw data in these tensors is serialized to a file
          # Thus serialize only if tensor has raw data and it was marked for serialization
          if uses_external_data(tensor) and tensor.HasField("raw_data"):
              save_external_data(tensor, filepath)
              tensor.ClearField("raw_data")
  
      return model
  
imports: import os
  import re
  import sys
  import uuid
  from itertools import chain
  from typing import Callable, Iterable, Optional
  from onnx.onnx_pb import AttributeProto, GraphProto, ModelProto, TensorProto
label_desc: Use image node_id 17 for calling a global function with example usage: write_external_data_tensors(model, filepath) and returns: model