Skip to main content

Decorator tracking

Track a Python function and link it to the next run.

Use @hub_run when a function represents one stage of your workflow. Each call opens a run and records its outcome. The function receives a Client as its first argument and uses it to log results.

Complete SDK setup first. For a block of code instead of a whole function, use Direct tracking.

Track a function#

from embedl_hub.tracking import Client, hub_run

client = Client()
client.set_project("quantized-classifier")

@hub_run("eval", name="Evaluate classifier")
def evaluate(client, model_id):
    client.log_param("model_id", model_id)
    client.log_tag("sample_data", "true")
    accuracy = 0.92  # Replace with the result of your evaluation.
    client.log_metric("accuracy", accuracy)
    return accuracy

result = evaluate(client, "classifier_int8_v1")
print(result.value)

The decorator marks the run finished when the function returns, failed when an exception escapes, or killed when interrupted. result is a Tracked value containing the function’s return value in .value and the recorded run in .run.

Connect stages#

Pass a Tracked result directly to another decorated function. It receives the underlying value, and its run points to the producing run as its parent:

@hub_run("compile")
def quantize(client, model_id):
    client.log_param("source_model", model_id)
    client.log_param("precision", "int8")
    return "classifier_int8_v1"

quantized = quantize(client, "classifier_fp32_v1")
evaluation = evaluate(client, quantized)

Add your actual quantization code inside quantize. Passing only quantized.value would discard the lineage information. The first direct Tracked argument with a recorded run supplies the parent. Values nested inside lists or dictionaries are not automatically unwrapped.

Open Lineage on a run to inspect the connection.

Upload files#

Use client.log_artifact(path) inside the function to attach an output file to its run. Create the file before uploading it. See Artifacts for uploading and finding files.

Next steps#