o
    ®Ÿ?e§  ã                   @   s®   d Z ddlmZ ddlmZ edƒ	ddd„ƒZed	ƒ		dd
d„ƒZedƒ	ddd„ƒZedƒ		ddd„ƒZedƒddd„ƒZ	edƒdd„ ƒZ
edƒ			d dd„ƒZdS )!zDmlir is an experimental library that provides support APIs for MLIR.é    )Úpywrap_mlir)Ú	tf_exportz#mlir.experimental.convert_graph_defútf-standard-pipelineFc                 C   ó   t  | ||¡S )aK  Import a GraphDef and convert it to a textual MLIR module.

  This API is only intended for inspecting the internals of TensorFlow and the
  string returned is at the moment intended for debugging purposes.

  Args:
    graph_def: An object of type graph_pb2.GraphDef or a textual proto
      representation of a valid GraphDef.
    pass_pipeline: A textual description of an MLIR Pass Pipeline to run on the
      module, see MLIR documentation for the [textual pass pipeline
      syntax](https://mlir.llvm.org/docs/PassManagement/#textual-pass-pipeline-specification).
    show_debug_info: Whether to include locations in the emitted textual form.

  Returns:
    A textual representation of the MLIR module corresponding to the graphdef.

  Raises:
    InvalidArgumentError: if graph_def is invalid or cannot be converted to
      MLIR.
  )r   Zimport_graphdef)Z	graph_defÚpass_pipelineÚshow_debug_info© r   úe/home/www/facesmatcher.com/pyenv/lib/python3.10/site-packages/tensorflow/python/compiler/mlir/mlir.pyÚconvert_graph_def   s   r
   z"mlir.experimental.convert_functionc                 C   r   )a¨  Import a ConcreteFunction and convert it to a textual MLIR module.

  This API is only intended for inspecting the internals of TensorFlow and the
  string returned is at the moment intended for debugging purposes.

  A [tf.function](https://www.tensorflow.org/api_docs/python/tf/function) can be
  imported and converted from TensorFlow to TensorFlow MLIR with this API by
  extracting its ConcreteFunction (eagerly-executing wrapper around a
  [tf.Graph](https://www.tensorflow.org/api_docs/python/tf/Graph)).

  For example:
  >>> @tf.function
  ... def add(a, b):
  ...   return a + b

  >>> concrete_function = add.get_concrete_function(
  ...     tf.TensorSpec(None, tf.dtypes.float32),
  ...     tf.TensorSpec(None, tf.dtypes.float32))
  >>> tf.mlir.experimental.convert_function(concrete_function)
  '...module attributes {...} {...}...'

  Args:
    concrete_function: An object of type ConcreteFunction.
    pass_pipeline: A textual description of an MLIR Pass Pipeline to run on the
      module, see MLIR documentation for the [textual pass pipeline
      syntax](https://mlir.llvm.org/docs/PassManagement/#textual-pass-pipeline-specification).
    show_debug_info: Whether to include locations in the emitted textual form.

  Returns:
    A textual representation of the MLIR module corresponding to the
    ConcreteFunction.

  Raises:
    InvalidArgumentError: if concrete_function is invalid or cannot be converted
      to MLIR.
  )r   Zimport_function)Zconcrete_functionr   r   r   r   r	   Úconvert_function0   s   *ÿr   z%mlir.experimental.convert_saved_modelc                 C   r   )a0  Converts a SavedModel to MLIR module.

  Args:
    saved_model_path: Path to SavedModel.
    exported_names: Names to export.
    show_debug_info: Whether to include locations in the emitted textual form.

  Returns:
    A textual representation of the MLIR module corresponding to the
    SavedModel.
  )r   Z(experimental_convert_saved_model_to_mlir)Úsaved_model_pathÚexported_namesr   r   r   r	   Úconvert_saved_model_   s   ÿr   z(mlir.experimental.convert_saved_model_v1Tc              	   C   s   t  | ||||||¡S )ax  Converts a v1 SavedModel to MLIR module.

  Args:
    saved_model_path: Path to SavedModel.
    exported_names: Names to export.
    tags: MetaGraphDef to be loaded is identified by the supplied tags.
    lift_variables: Whether to promote tf.VarHandleOp to resource arguments.
    include_variables_in_initializers: Keeps the variables in initializers
      before lifting variables.
    upgrade_legacy: Functionalize the input graph before importing.
    show_debug_info: Whether to include locations in the emitted textual form.

  Returns:
    A textual representation of the MLIR module corresponding to the
    SavedModule.
  )r   Z#experimental_convert_saved_model_v1)r   r   ÚtagsZlift_variablesZ!include_variables_in_initializersZupgrade_legacyr   r   r   r	   Úconvert_saved_model_v1s   s   ùr   z#mlir.experimental.run_pass_pipelinec                 C   r   )aR  Runs a pipeline over input module.

  Args:
    mlir_txt: Textual representation of the MLIR module.
    pass_pipeline: Pass pipeline to run on module.
    show_debug_info: Whether to include locations in the emitted textual form.

  Returns:
    A textual representation of the MLIR module corresponding to the
    transformed module.
  )r   Zexperimental_run_pass_pipeline)Úmlir_txtr   r   r   r   r	   Úrun_pass_pipeline˜   s   ÿr   z mlir.experimental.write_bytecodec                 C   s   t  | |¡ dS )z‹Writes an MLIR module out as bytecode.

  Args:
    filename: The filename to write to.
    mlir_txt: The MLIR module in textual format.
  N)r   Úexperimental_write_bytecode)Úfilenamer   r   r   r	   r   ª   s   r   z)mlir.experimental.tflite_to_tosa_bytecodeNc                 C   s   t  | ||||¡ dS )a©  Converts TFLite flatbuffer to TOSA dialect in MLIR bytecode.

  Args:
    flatbuffer: Path to flatbuffer.
    bytecode: Path to output bytecode.
    use_external_constant: Whether to create `tfl.external_const` instead of
      `tfl.const`.
    ordered_input_arrays:
    ordered_output_arrays: If ordered_output_arrays is not empty, then the
      function will only return nodes in ordered_output_arrays in the same order
  N)r   Z$experimental_tflite_to_tosa_bytecode)Z
flatbufferÚbytecodeZuse_external_constantZordered_input_arraysZordered_output_arraysr   r   r	   Útflite_to_tosa_bytecodeµ   s   ûr   )r   F)F)TF)FNN)Ú__doc__Ztensorflow.pythonr   Z tensorflow.python.util.tf_exportr   r
   r   r   r   r   r   r   r   r   r   r	   Ú<module>   s4   ÿý.ÿù$

û