Beispiel #1
0
def get_trainer_jsonschema():
    def allowed_types_for_trainer_schema(cls) -> List[str]:
        """Returns the allowed values for the "type" field on the given trainer schema."""
        return cls.Schema().fields[TYPE].validate.choices

    conds = []
    all_trainer_types = []
    for trainer in trainer_schema_registry:
        trainer_cls = trainer_schema_registry[trainer]

        allowed_trainer_types = allowed_types_for_trainer_schema(trainer_cls)
        all_trainer_types.extend(allowed_trainer_types)

        other_props = schema_utils.unload_jsonschema_from_marshmallow_class(trainer_cls)["properties"]
        other_props.pop("type")
        for trainer_type in allowed_trainer_types:
            trainer_cond = schema_utils.create_cond(
                {"type": trainer_type},
                other_props,
            )
            conds.append(trainer_cond)

    return {
        "type": "object",
        "properties": {
            "type": {"type": "string", "enum": all_trainer_types},
        },
        "title": "trainer_options",
        "allOf": conds,
        "description": "Use type 'trainer' for training ECD models, or 'lightgbm_trainer' for Tree models.",
    }
def test_torch_description_pull():
    example_empty_desc_prop = schema_utils.unload_jsonschema_from_marshmallow_class(
        lso.AdamOptimizerConfig)["properties"]["lr"]
    assert (isinstance(example_empty_desc_prop, dict)
            and "description" in example_empty_desc_prop
            and isinstance(example_empty_desc_prop["description"], str)
            and len(example_empty_desc_prop["description"]) > 3)
Beispiel #3
0
 def _jsonschema_type_mapping():
     preprocessor_cls = preprocessing_registry[feature_type]
     props = schema_utils.unload_jsonschema_from_marshmallow_class(
         preprocessor_cls)["properties"]
     return {
         "type": "object",
         "properties": props,
         "additionalProperties": False,
     }
Beispiel #4
0
def get_combiner_conds():
    """Returns a list of if-then JSON clauses for each combiner type in `combiner_registry` and its properties'
    constraints."""
    combiner_types = sorted(list(combiner_registry.keys()))
    conds = []
    for combiner_type in combiner_types:
        combiner_cls = combiner_registry[combiner_type]
        schema_cls = combiner_cls.get_schema_cls()
        combiner_schema = schema_utils.unload_jsonschema_from_marshmallow_class(
            schema_cls)
        combiner_props = combiner_schema["properties"]
        combiner_cond = schema_utils.create_cond({"type": combiner_type},
                                                 combiner_props)
        conds.append(combiner_cond)
    return conds
Beispiel #5
0
def get_optimizer_conds():
    """Returns a JSON schema of conditionals to validate against optimizer types defined in
    `ludwig.modules.optimization_modules.optimizer_registry`."""
    conds = []
    for optimizer in optimizer_registry:
        optimizer_cls = optimizer_registry[optimizer][1]
        other_props = unload_jsonschema_from_marshmallow_class(
            optimizer_cls)["properties"]
        other_props.pop("type")
        preproc_cond = create_cond(
            {"type": optimizer},
            other_props,
        )
        conds.append(preproc_cond)
    return conds
Beispiel #6
0
def get_input_feature_conds():
    """This function returns a list of if-then JSON clauses for each input feature type along with their properties
    and constraints.

    Returns: List of JSON clauses
    """
    input_feature_types = sorted(list(input_type_registry.keys()))
    conds = []
    for feature_type in input_feature_types:
        feature_cls = input_type_registry[feature_type]
        schema_cls = feature_cls.get_schema_cls()
        feature_schema = schema_utils.unload_jsonschema_from_marshmallow_class(schema_cls)
        feature_props = feature_schema["properties"]
        update_encoders(feature_props, feature_type)
        feature_cond = schema_utils.create_cond({"type": feature_type}, feature_props)
        conds.append(feature_cond)
    return conds
Beispiel #7
0
 def _jsonschema_type_mapping(self):
     return {
         "oneOf": [
             {
                 "type": "null",
                 "title": "disabled",
                 "description": "Disable gradient clipping."
             },
             {
                 **unload_jsonschema_from_marshmallow_class(GradientClippingConfig), "title":
                 "enabled_options"
             },
         ],
         "title":
         "gradient_clipping_options",
         "description":
         description,
     }