Migrating to SDK v0.5
Learn how to migrate to the latest version of the Qwak Python SDK.
About v0.5
This version brings a multitude of improvements, new features, and enhanced performance, all aimed at providing you with an even better Qwak experience.
With v0.5, we introduce the qwak-sdk
as a public Python package. We reduced package dependencies and refactored the codebase to make it more lightweight.
While these changes bring many benefits, they also introduce breaking changing that require minor modifications to your existing codebase.
Installing the new SDK
Please note that Qwak currently supports Python versions 3.7.x to 3.9.x.
Starting v0.5, the qwak-sdk
can be found on the public PyPI package repository. All you need is to run:
pip install qwak-sdk
Alternatively, when upgrading an existing qwak-sdk
installation, run the following command:
pip install --upgrade qwak-sdk
Models SDK
QwakModelInterface
became QwakModel
QwakModelInterface
became QwakModel
We simplified the name of the main Qwak model class, renaming QwakModelInterface
to QwakModel
.
New Qwak SDK v0.5
from qwak.model.base import QwakModel
class NewPredicitionModel(QwakModel):
def __init__(self):
pass
Qwak SDK v0.9
from qwak.model.base import QwakModelInterface
class OldPredicitionModlel(QwakModelInterface):
def __init__(self):
pass
Locally testing models
We updated the way to local test and debug models. Please note that run_local
method is now imported externally from from qwak.model.tools import run_local
New Qwak SDK v0.5
from qwak.model.tools import run_local
model = MyQwakModel()
input_vector = DataFrame(
[{
"prompt": "Why does it matter if a Central Bank has a negative rather than 0% interest rate?"
}]
).to_json()
prediction = run_local(m, input_vector)
Qwak SDK v0.9
from qwak.model.tools import run_local
model = MyQwakModel()
input_vector = DataFrame(
[{
"prompt": "Why does it matter if a Central Bank has a negative rather than 0% interest rate?"
}]
).to_json()
precidtion = model.run_local(input_vector)
Model schema updates
The model schema defines your model's inputs and outputs.
The Prediction
class has changed to InferenceOutput
with the same import paths.
features
, predictions
were changed to inputs
and outputs
New Qwak SDK v0.5
from qwak.model.base import QwakModel
from qwak.model.schema import ModelSchema, ExplicitFeature, InferenceOutput
class NewModelWithSchema(QwakModel):
def schema(self):
model_schema = ModelSchema(
inputs=[
ExplicitFeature(name="User_Name", type=str),
ExplicitFeature(name="Duration", type=int),
],
outputs=[
InferenceOutput(name="Churn_Probability", type=float)
])
return model_schema
Qwak SDK v0.9
from qwak.model.base import QwakModelInterface
from qwak.model.schema import ModelSchema, ExplicitFeature, InferenceOutput
class ModelWithSchema(QwakModelInterface):
def schema(self):
model_schema = ModelSchema(
features=[
ExplicitFeature(name="User_Name", type=str),
ExplicitFeature(name="Duration", type=int),
],
predictions=[
Prediction(name="Churn_Probability", type=float)
])
return model_schema
Unifying test mocks
Integration tests mocks were imported from a separate qwak_mock
package, which is now deprecated.
All mock modules moved under qwak.testing
in the main qwak
package.
New Qwak SDK v0.5
from qwak.testing.fixtures import real_time_client
def test_realtime_api(real_time_client):
feature_vector = [
{
'text': 'To the Moon!'
}]
real_time_client.predict(feature_vector)
Qwak SDK v0.9
from qwak_mock import real_time_client
def test_realtime_api(real_time_client):
feature_vector = [
{
'text': 'To the Moon!'
}]
real_time_client.predict(feature_vector)
Qwak Secret Service
Retrieving qwak secrets is now changed from SecretServiceGrpcClient
to SecretServiceClient
New Qwak SDK v0.5
from qwak import QwakModel
from qwak.clients.secret_service import SecretServiceClient
class TestModel(QwakModel)
# ...
def build():
secret_service = SecretServiceClient()
aws_api_key = secret_service.get_secret('aws_api_key')
aws_secret_key = secret_service.get_secret('aws_secret_key')
Qwak SDK v0.9
from qwak import QwakModelInterface
from qwak.secret_service.client import SecretServiceGrpcClient
class TestModel(QwakModel)
# ...
def build():
secrets_client = SecretServiceGrpcClient()
aws_api_key = secret_service.get_secret('aws_api_key')
aws_secret_key = secret_service.get_secret('aws_secret_key')
qwak-inference
package
qwak-inference
packageThe RealTimeClient
to test deployed models moved to a separate package.
By doing that, we removed dependencies from the main qwak-sdk
package and simplified the installation.
New Qwak SDK v0.5
First install the below Python package:
pip install qwak-inference
from qwak_inference import RealTimeClient
QWAK_MODEL_ID = 'text-summarizer'
if __name__ == '__main__':
feature_vector = [
{
"text" : "Please summarize this sentence",
}
]
client = RealTimeClient(model_id=QWAK_MODEL_ID)
response = client.predict(feature_vector)
Qwak SDK v0.9
from qwak.inference.clients import RealTimeClient
QWAK_MODEL_ID = 'text-summarizer'
if __name__ == '__main__':
feature_vector = [
{
"text" : "Please summarize this sentence",
}
]
client = RealTimeClient(model_id=QWAK_MODEL_ID)
response = client.predict(feature_vector)
CLI updates
Simplifying model creation
Creating new models and projects required two commands. We merged them into one, and made description optional.
New Qwak SDK v0.5
qwak models create “Credit Risk” --project “Credit Risk Modeling”
Qwak SDK v0.9
qwak projects create --project-name "Credit Risk Modeling" --project-description "An example project"
qwak models create --project-id <your-project-id> --model-name "Credit Risk" --model-description "An example model"
Automatic build and deploy
Deploy models automatically in a single command using qwak models build
and the --deploy
parameter.
New Qwak SDK v0.5
qwak models build ./credit_risk --model-id "credit_risk" --deploy
Qwak SDK v0.9
qwak models build ./credit_risk --model-id "credit_risk"
qwak models deploy realtime --model-id "credit_risk" --build-id <your-build-id>
Feature Store SDK
Batch Feature Set import paths
New Qwak SDK v0.5
from qwak.feature_store.feature_sets import batch
from qwak.feature_store.feature_sets.transformations import SparkSqlTransformation
from qwak.feature_store.feature_sets.execution_spec import ClusterTemplate
from qwak.feature_store.feature_sets.read_policies import ReadPolicy
Qwak SDK v0.9
from qwak.feature_store.v1 import batch, SparkSqlTransformation
from qwak.feature_store.features.execution_spec import ClusterTemplate
from qwak.feature_store.features import ReadPolicy
Data source import path
We simplified the import path of all data sources to qwak.feature_store.data_sources
.
New Qwak SDK v0.5
from qwak.feature_store.data_sources import CsvSource, SnowflakeSource
Qwak SDK v0.9
from qwak.feature_store.sources.data_sources import CsvSource, SnowflakeSource
Offline & Online Client
Offline Client was changed to from qwak.feature_store.offline import OfflineClient
.
New Qwak SDK v0.5
from qwak.feature_store.offline import OfflineClient
offline_feature_store = OfflineClient()
Qwak SDK v0.9
from qwak.feature_store.offline import OfflineFeatureStore
offline_feature_store = OfflineFeatureStore()
Updated about 10 hours ago