Skip to main content

Opinionated machine learning organization and configuration

Project description

microcosm-sagemaker

Opinionated machine learning with SageMaker

Usage

For best practices, see cookiecutter-microcosm-sagemaker.

Profiling

Make sure pyinstrument is installed, either using pip install pyinstrument or by installing microcosm-sagemaker with profiling extra dependencies:

pip install -e '.[profiling]'

To enable profiling of the app, use the --profile flag with runserver:

runserver --profile

The service will log that it is in profiling mode and announce the directory to which it is exporting. Each call to the endpoint will be profiled and its results with be stored in a time-tagged html file in the profiling directory.

Experiment Tracking

To use Weights and Biases, install microcosm-sagemaker with wandb extra depdency:

pip install -e '.[wandb]'

To enable experiment tracking in an ML repository:

  • Choose the experiment tracking stores for your ML model. It is recommended to store metrics in both wandb and Amazon cloudwatch. To do so, add wandb and cloudwatch to graph.use() in app_hooks/train/app.py and app_hooks/evaluate/app.py.

  • Add the API key for wandb to your ML model's config.json file:

{
    "wandb": {
        "api_key": "XXXXXX"
    }
}
  • To define hyperparameters for your model:
from microcosm.api import defaults, binding
from microcosm_sagemaker.bundle import Bundle
from microcosm_sagemaker.hyperparameters import hyperparameter

@binding("my_classifier")
@defaults(
    param = 10,
    hyperparam = hyperparameter(20),
)
class MyClassifier(Bundle):
    ...

That automatically adds the hyperparameters to your experiment, which simplifies hyperparameter optimization and tuning.

  • To report a static metric:
class MyClassifier(Bundle):
    ...

    def fit(self, input_data):
        ...
        self.experiment_metrics.log_static(<metric_name>=<metric_value>)
  • To report a time-series metric:
class MyClassifier(Bundle):
    ...

    def fit(self, input_data):
        ...
        self.experiment_metrics.log_timeseries(
            <metric_name>=<metric_value>,
            step=<step_number>
        )

Note that the step keyword argument must be provided for logging time-series.

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

microcosm-sagemaker-0.2071.dev2071.tar.gz (26.2 kB view details)

Uploaded Source

File details

Details for the file microcosm-sagemaker-0.2071.dev2071.tar.gz.

File metadata

  • Download URL: microcosm-sagemaker-0.2071.dev2071.tar.gz
  • Upload date:
  • Size: 26.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.8.0 tqdm/4.45.0 CPython/3.7.7

File hashes

Hashes for microcosm-sagemaker-0.2071.dev2071.tar.gz
Algorithm Hash digest
SHA256 fa2bd590ae00ecf7084a964872225eba9fb6da2707d00e6c70aebde13181ca4a
MD5 d41585fe0f06ec402f0cb55fe080dd38
BLAKE2b-256 d84a5b63a9917f73ea04168b88dd34a396ffbdb7a154937d30bd5fb94e3f5c17

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page