Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ExposedModel to produce predictions #24

Merged
merged 13 commits into from
Apr 16, 2024
Merged

Conversation

MatsMoll
Copy link
Owner

@MatsMoll MatsMoll commented Apr 2, 2024

The main feature was to add a way to define exposed models.

This makes it easier to find out where a model contract can be used, and how to use the model.
Therefore, the main purpose is to answer the following questions:

  • Where are our models located? An API, model registry, etc?
  • Which kind of format do we expect to provide in order to use the model? JSON column wise, row wise, protobuf?
@model_contract(
    input_features=[...],
    exposed_model=ExposedModel.in_memory_mlflow(
        model_name="taxi_eta",
        model_alias="Champion",

        prediction_column="predicted_eta",
        predicted_at_column="predicted_at",
        model_version_column="model_version",
        model_contract_version_tag=None  # Since there are no versions, will this mean the literal array
    )
)
class TaxiRegressionModel:
    trip_id = String().as_entity()
    predicted_eta = Float()
    predicted_at = EventTimestamp()
    model_version = String().as_model_version()

However, this also means that we can potentially use the modells with the following:

store = await FeatureStore.from_dir()
preds = await store.model("taxi_eta").predict_over({
    "trip_id": [...],
}).to_polars()

Or store them in the output source directly?

store = await FeatureStore.from_dir()
await store.model("taxi_eta").predict_over({
    "trip_id": [...],
}).upsert_into_output_source()

This also lead to the development of some generated Ollama contracts:

from aligned.exposed_models.ollama import ollama_classification_contract, ollama_embedding_contract

Classification = ollama_classification_contract(
    contract_name="some_classification",
    inputs=[features.x, features.y, features.z],
    prompt_template="You are ... you have {x}, {y}, and {z}, is it true or false?",
    ground_truth=features.a,
    entities=[features.row_id],
    output_source=FileSource.parquet(...),
    endpoint="ollama_endpoint",
)

Other improvements:

  • Added a loaded_columns to not load more data than needed.

@MatsMoll MatsMoll merged commit bc88a2a into main Apr 16, 2024
1 check passed
@MatsMoll MatsMoll deleted the matsei/exposed-models branch April 16, 2024 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant