Skip to main content

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. Currently, we only support wandb. To do so, add wandb to graph.use() in app_hooks/train/app.py and app_hooks/evaluate/app.py.

  • Add the API key for wandb to the environment variables injected by Circle CI into the docker instance, by visiting https://circleci.com/gh/globality-corp/<MODEL-NAME>/edit#env-vars and adding WANDB_API_KEY as an environment variable.

  • Microcosm-sagemaker automatically adds the config for the active bundle and its dependents to the wandb's run config.

  • 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.

Artifact Tests

If you want to report your artifact tests to wandb, add the following line to the top of your conftest.py. For more information on using plugins in pytest, see here.

pytest_plugins = 'pytest_sagemaker'

It should be generated by globality-build, but in case it is not, also make sure to run artifact tests with --capture=tee-sys. This will allow to both capture and show stdout.

Reproducibility

As recommended here, we seed Python, Numpy and Pytorch random number generators and force Pytorch operations to be deterministic. See microcosm-sagemaker/random.py for details.

Distributed training

To support "distributed" trainin - with multiple processes (like pytorch DistributedDataParallel), we detect if the current process is a "worker process" (non-master member of a process group). Worker processes are prevented from communicating with the outside world - writing logs and saving artifacts.

Release files for microcosm-sagemaker 0.9.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for microcosm-sagemaker 0.9.5
File Size Uploaded
microcosm-sagemaker-0.9.5.tar.gz 27.2 kB Details

Release files / microcosm-sagemaker-0.9.5.tar.gz

Download URL microcosm-sagemaker-0.9.5.tar.gz
Size 27.2 kB
Tags Source
SHA-256 checksum
How to use checksums
0c4c71857c76e9fd52a76eca9ff634267dd033e344ad0294ebddd39cd03c4b85
BLAKE2b-256 checksum
How to use checksums
85be23d9dd0f34034610854646d1f803eb1f634bb2e2913f4200ad66cb1383e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.10.1 keyring/21.8.0 rfc3986/2.0.0 colorama/0.4.3 CPython/3.7.12

Release history Release notifications | RSS feed

This release

0.9.5 This release

1 release file

0.9.4

1 release file

0.9.3

1 release file

0.9.2

1 release file

0.9.1

1 release file

0.9.0

1 release file

0.8.13

1 release file

0.8.12

1 release file

0.8.10

1 release file

0.8.9

1 release file

0.8.7

1 release file

0.8.6

1 release file

0.8.5

1 release file

0.8.4

1 release file

0.8.3

1 release file

0.8.2

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.1

1 release file

0.6.0

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.3

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page