Beispiel #1
0
def test_scope():
    assert context.get_training_metrics() == set()
    with context.metrics_scope(["flip_ratio"]):
        assert context.get_training_metrics() == {"flip_ratio"}
    assert context.get_training_metrics() == set()
    with pytest.raises(ValueError, match=r".*unknown_metric.*"):
        with context.metrics_scope(["flip_ratio", "unknown_metric"]):
            pass
Beispiel #2
0
def get_kernel_quantizer(identifier):
    """Returns a quantizer from identifier and adds default kernel quantizer metrics.

    # Arguments
        identifier: Function or string

    # Returns
        `Quantizer` or `None`
    """
    quantizer = get(identifier)
    if isinstance(quantizer, BaseQuantizer) and not quantizer._custom_metrics:
        quantizer._custom_metrics = list(context.get_training_metrics())
    return quantizer