示例#1
0
    def update_model_card_json(
            self, model_card: model_card_module.ModelCard) -> None:
        """Validates the model card and updates the JSON file in MCT assets.

    If model_card.schema_version is not provided, it will assign the latest
    schema version to the `model_card`, and validate it.

    Args:
      model_card: The updated model card that users want to write back.

    Raises:
       Error: when the given model_card is invalid w.r.t. the schema.
    """
        if not model_card.schema_version:
            sub_directories = [
                f for f in os.scandir(_SCHEMA_DIR) if f.is_dir()
            ]
            latest_schema_version = max(
                sub_directories,
                key=lambda f: semantic_version.Version(f.name[1:]))
            model_card.schema_version = latest_schema_version.name[1:]
        # Validate the updated model_card first.
        schema = self._find_model_card_schema(model_card.schema_version)
        jsonschema.validate(model_card.to_dict(), schema)
        # Write the updated JSON to the file.
        self._write_file(self._mcta_json_file, model_card.to_json())
示例#2
0
 def test_full_filled_model_card_is_valid_json(self):
     model_card = ModelCard()
     model_card.schema_version = '0.0.1'
     self._fill_model_details(model_card)
     self._fill_model_parameters(model_card)
     self._fill_quantitative_analysis(model_card)
     self._fill_considerations(model_card)
     self._validate_schema(model_card)
示例#3
0
 def test_default_value_not_shared_among_model_cards(self):
     model_card = ModelCard()
     model_card.schema_version = '0.0.1'
     self._fill_model_details(model_card)
     self._fill_model_parameters(model_card)
     self._fill_quantitative_analysis(model_card)
     self._fill_considerations(model_card)
     other_model_card = ModelCard()
     self.assertNotEqual(other_model_card, model_card)
     self.assertEqual(other_model_card, ModelCard())
示例#4
0
    def update_model_card_json(self, model_card: ModelCard) -> None:
        """Validates the model card and updates the JSON file in MCT assets.

    If model_card.schema_version is not provided, it will assign the latest
    schema version to the `model_card`, and validate it.

    Args:
      model_card: The updated model card that users want to write back.

    Raises:
       Error: when the given model_card is invalid w.r.t. the schema.
    """
        if not model_card.schema_version:
            model_card.schema_version = validation.get_latest_schema_version()
        validation.validate_json_schema(model_card.to_dict(),
                                        model_card.schema_version)
        self._write_file(self._mcta_json_file, model_card.to_json())
示例#5
0
 def test_model_card_with_model_parameters_is_valid_json(self):
     model_card = ModelCard()
     model_card.schema_version = '0.0.1'
     self._fill_model_parameters(model_card)
     self._validate_schema(model_card)
示例#6
0
 def test_model_card_with_considerations_is_valid_json(self):
     model_card = ModelCard()
     model_card.schema_version = '0.0.1'
     self._fill_considerations(model_card)
     self._validate_schema(model_card)
示例#7
0
 def test_model_card_with_quantitative_analysis_is_valid_json(self):
     model_card = ModelCard()
     model_card.schema_version = '0.0.1'
     self._fill_quantitative_analysis(model_card)
     self._validate_schema(model_card)