Ejemplo n.º 1
0
def refactor_model_blessing(model_blessing: artifact.Artifact,
                            name_from_id: Mapping[int, str]) -> None:
    """Changes id-typed custom properties to string-typed runtime artifact name."""
    if model_blessing.has_custom_property(
            constants.ARTIFACT_PROPERTY_BASELINE_MODEL_ID_KEY):
        model_blessing.set_string_custom_property(
            constants.ARTIFACT_PROPERTY_BASELINE_MODEL_ID_KEY,
            _get_full_name(artifact_id=model_blessing.get_int_custom_property(
                constants.ARTIFACT_PROPERTY_BASELINE_MODEL_ID_KEY),
                           name_from_id=name_from_id))
    if model_blessing.has_custom_property(
            constants.ARTIFACT_PROPERTY_CURRENT_MODEL_ID_KEY):
        model_blessing.set_string_custom_property(
            constants.ARTIFACT_PROPERTY_CURRENT_MODEL_ID_KEY,
            _get_full_name(artifact_id=model_blessing.get_int_custom_property(
                constants.ARTIFACT_PROPERTY_CURRENT_MODEL_ID_KEY),
                           name_from_id=name_from_id))
Ejemplo n.º 2
0
def is_artifact_version_older_than(artifact: Artifact,
                                   artifact_version: Text) -> bool:
  """Check if artifact belongs to old version."""
  if artifact.mlmd_artifact.state == metadata_store_pb2.Artifact.UNKNOWN:
    # Newly generated artifact should use the latest artifact payload format.
    return False

  # For artifact that resolved from MLMD.
  if not artifact.has_custom_property(ARTIFACT_TFX_VERSION_CUSTOM_PROPERTY_KEY):
    # Artifact without version.
    return True

  if (version.parse(
      artifact.get_string_custom_property(
          ARTIFACT_TFX_VERSION_CUSTOM_PROPERTY_KEY)) <
      version.parse(artifact_version)):
    # Artifact with old version.
    return True
  else:
    return False
Ejemplo n.º 3
0
def _get_data_view_info(
        examples: artifact.Artifact) -> Optional[Tuple[str, int]]:
    """Returns the payload format and data view URI and ID from examples."""
    assert examples.type is standard_artifacts.Examples, (
        'examples must be of type standard_artifacts.Examples')
    payload_format = examples_utils.get_payload_format(examples)
    if payload_format == example_gen_pb2.PayloadFormat.FORMAT_PROTO:
        data_view_uri = examples.get_string_custom_property(
            constants.DATA_VIEW_URI_PROPERTY_KEY)
        if data_view_uri:
            assert examples.has_custom_property(
                constants.DATA_VIEW_CREATE_TIME_KEY)
            # The creation time could be an int or str. Legacy artifacts will contain
            # an int custom property.
            data_view_create_time = examples.get_custom_property(
                constants.DATA_VIEW_CREATE_TIME_KEY)
            data_view_create_time = int(data_view_create_time)
            return data_view_uri, data_view_create_time

    return None