Skip to content

Commit c234fb4

Browse files
authored
Merge pull request #8 from zeroae/f/sagemaker
Add SageMaker Inference Toolkit support
2 parents be33521 + 59be296 commit c234fb4

18 files changed

+411
-17
lines changed

.github/condarc.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
anaconda_upload: false
22
channels:
33
- zeroae
4-
- defaults
54
- conda-forge
6-
show_channel_urls: true
5+
show_channel_urls: true

.github/workflows/pypa-conda.yml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ jobs:
2222
strategy:
2323
matrix:
2424
os: [ubuntu-latest]
25-
python-version: [3.6]
25+
python-version: [3.7]
2626
black-version: [19.10b]
2727
flake8-version: [3.7.9]
2828
runs-on: ${{ matrix.os }}
2929
steps:
3030
- uses: actions/checkout@v1
31-
- uses: actions/setup-python@v1.1.1
31+
- uses: actions/setup-python@v2.2.2
3232
with:
3333
python-version: ${{ matrix.python-version }}
3434
- uses: actions/cache@v1
@@ -75,7 +75,7 @@ jobs:
7575
rm -f *.tar.gz
7676
7777
# Create the bdist wheel file
78-
- uses: actions/setup-python@v1.1.1
78+
- uses: actions/setup-python@v2.2.2
7979
- uses: actions/cache@v1
8080
id: cache
8181
with:
@@ -152,7 +152,7 @@ jobs:
152152

153153
#
154154
# Setup the test environment, python + .whl + .whl[test]
155-
- uses: actions/setup-python@v1.1.1
155+
- uses: actions/setup-python@v2.2.2
156156
with:
157157
python-version: ${{ matrix.python-version }}
158158
- name: Get pip cache
@@ -211,13 +211,16 @@ jobs:
211211
tar -xvf *.tar.gz --strip 1
212212
rm *.tar.gz
213213
214-
- uses: goanpeca/setup-miniconda@v1
214+
- uses: conda-incubator/setup-miniconda@v2
215215
with:
216216
activate-environment: ''
217217
auto-activate-base: true
218-
conda-build-version: 3.18
218+
miniforge-variant: Mambaforge
219+
use-mamba: true
220+
conda-build-version: 3.21.4
219221
condarc-file: .github/condarc.yml
220-
- run: conda install setuptools_scm conda-verify
222+
- run: |
223+
mamba install setuptools_scm conda-verify boa
221224
- uses: actions/cache@v1
222225
id: conda-pkgs-cache
223226
with:
@@ -228,7 +231,7 @@ jobs:
228231
- name: Run conda build
229232
run: |
230233
mkdir conda-bld
231-
conda build --output-folder conda-bld .
234+
conda mambabuild --output-folder conda-bld .
232235
env:
233236
ANACONDA_API_TOKEN: ${{ secrets.ANACONDA_API_TOKEN }}
234237
- name: Create conda-bld/manifest
@@ -338,7 +341,7 @@ jobs:
338341
with:
339342
path: /usr/share/miniconda/pkgs
340343
key: ${{ runner.os }}-conda-ac1.7.2
341-
- uses: goanpeca/setup-miniconda@v1
344+
- uses: conda-incubator/setup-miniconda@v2
342345
with:
343346
activate-environment: ''
344347
auto-activate-base: true

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# MacOS
2+
.DS_Store
3+
4+
# Vagrant
5+
.vagrant
6+
17
# Byte-compiled / optimized / DLL files
28
__pycache__/
39
*.py[cod]

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ wheels: dist ## downloads wheel dependencies
9393
ls -l wheels
9494

9595
dist-conda: ## builds conda-package
96-
conda build --no-anaconda-upload --output-folder conda-bld \
96+
conda mambabuild --no-anaconda-upload --output-folder conda-bld \
9797
-c zeroae \
9898
-c conda-forge \
99-
-c anaconda .
99+
.
100100

101101
install: clean ## install the package to the active Python's site-packages
102-
python setup.py install
102+
python setup.py install

Vagrantfile

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# -*- mode: ruby -*-
2+
# vi: set ft=ruby :
3+
4+
# All Vagrant configuration is done below. The "2" in Vagrant.configure
5+
# configures the configuration version (we support older styles for
6+
# backwards compatibility). Please don't change it unless you know what
7+
# you're doing.
8+
Vagrant.configure("2") do |config|
9+
# The most common configuration options are documented and commented below.
10+
# For a complete reference, please see the online documentation at
11+
# https://docs.vagrantup.com.
12+
13+
# Every Vagrant development environment requires a box. You can search for
14+
# boxes at https://vagrantcloud.com/search.
15+
config.vm.box = "hashicorp/bionic64"
16+
17+
# Disable automatic box update checking. If you disable this, then
18+
# boxes will only be checked for updates when the user runs
19+
# `vagrant box outdated`. This is not recommended.
20+
# config.vm.box_check_update = false
21+
22+
# Create a forwarded port mapping which allows access to a specific port
23+
# within the machine from a port on the host machine. In the example below,
24+
# accessing "localhost:8080" will access port 80 on the guest machine.
25+
# NOTE: This will enable public access to the opened port
26+
config.vm.network "forwarded_port", guest: 8888, host: 8888
27+
28+
# Create a forwarded port mapping which allows access to a specific port
29+
# within the machine from a port on the host machine and only allow access
30+
# via 127.0.0.1 to disable public access
31+
# config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"
32+
33+
# Create a private network, which allows host-only access to the machine
34+
# using a specific IP.
35+
# config.vm.network "private_network", ip: "192.168.33.10"
36+
37+
# Create a public network, which generally matched to bridged network.
38+
# Bridged networks make the machine appear as another physical device on
39+
# your network.
40+
# config.vm.network "public_network"
41+
42+
# Share an additional folder to the guest VM. The first argument is
43+
# the path on the host to the actual folder. The second argument is
44+
# the path on the guest to mount the folder. And the optional third
45+
# argument is a set of non-required options.
46+
# config.vm.synced_folder "../data", "/vagrant_data"
47+
48+
# Provider-specific configuration so you can fine-tune various
49+
# backing providers for Vagrant. These expose provider-specific options.
50+
# Example for VirtualBox:
51+
#
52+
# config.vm.provider "virtualbox" do |vb|
53+
# # Display the VirtualBox GUI when booting the machine
54+
# vb.gui = true
55+
#
56+
# # Customize the amount of memory on the VM:
57+
# vb.memory = "1024"
58+
# end
59+
#
60+
# View the documentation for the provider you are using for more
61+
# information on available options.
62+
config.vm.provider "vmware_desktop" do |v|
63+
v.vmx["memsize"] = "2048"
64+
end
65+
66+
# Enable provisioning with a shell script. Additional provisioners such as
67+
# Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
68+
# documentation for more information about their specific syntax and use.
69+
config.vm.provision "shell", name: "Install Mambaforge", privileged: false, reset: true, inline: <<-SHELL
70+
MAMBA_FORGE_FILE=Mambaforge-$(uname)-$(uname -m).sh
71+
if ! [ -d ~/mambaforge ]; then
72+
if ! [ -f $MAMBA_FORGE_FILE ]; then
73+
wget -q https://github.com/conda-forge/miniforge/releases/latest/download/$MAMBA_FORGE_FILE
74+
fi
75+
bash $MAMBA_FORGE_FILE -b -u
76+
rm -f $MAMBA_FORGE_FILE
77+
78+
mambaforge/bin/conda init --all
79+
fi
80+
SHELL
81+
82+
config.vm.provision "shell", name: "Install OS Packages", inline: <<-SHELL
83+
### Add OpenJDK 8
84+
apt-get update
85+
apt-get --yes install openjdk-8-jre-headless
86+
SHELL
87+
88+
config.vm.provision "shell", name: "Create Development Environment", privileged: false, inline: <<-SHELL
89+
### Create the DarkNet Environment
90+
source mambaforge/etc/profile.d/conda.sh
91+
mamba env update --name darknet-cpu -f /vagrant/environment.yml
92+
echo 'conda activate darknet-cpu' >> ~/.bashrc
93+
SHELL
94+
end

environment.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
name: darknet.py-dev
32
channels:
43
- zeroae
@@ -9,6 +8,8 @@ dependencies:
98
- pip
109
- pip:
1110
- -e .
11+
- multi-model-server
12+
- sagemaker-inference
1213

1314
# Setup Requirements (setup.py:setup_requirements)
1415
- compilers
@@ -21,7 +22,7 @@ dependencies:
2122
# Install Requirements (setup.py:requirements)
2223
- click >=7.0
2324
- click-plugins
24-
- darknet
25+
- darknet-cpu
2526
- entrypoints
2627
- fsspec <=0.7.5
2728
- numpy
@@ -30,6 +31,12 @@ dependencies:
3031
# Zoo Optional Requirements
3132
- intake
3233

34+
# MMS Requirements
35+
- enum-compat
36+
- future
37+
- retrying
38+
- scipy
39+
3340
# Test Requirements (setup.py:test_requirements)
3441
- pytest >=3
3542
- pytest-cov

setup.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@
4747
# fmt: on
4848
]
4949

50+
mms_requirements = [
51+
# fmt: off
52+
"future",
53+
"multi-model-server",
54+
"retrying",
55+
"sagemaker-inference",
56+
# fmt: on
57+
]
5058
zoo_requirements = [
5159
# fmt: off
5260
"intake",
@@ -130,7 +138,7 @@
130138
long_description_content_type="text/x-rst",
131139
include_package_data=True,
132140
keywords="py darknet",
133-
name="darknet-py",
141+
name="darknet.py",
134142
package_dir={"": "src"},
135143
packages=find_namespace_packages(where="./src"),
136144
setup_requires=setup_requirements,
@@ -141,6 +149,7 @@
141149
"test": test_requirements,
142150
"doc": doc_requirements,
143151
"zoo": zoo_requirements,
152+
"mms": mms_requirements,
144153
# fmt: on
145154
},
146155
url="https://github.com/zeroae/darknet.py",

src/darknet/sagemaker/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .default_inference_handler import DefaultDarknetInferenceHandler, Network
2+
from ..py.util import image_to_3darray
3+
4+
__all__ = ["DefaultDarknetInferenceHandler", "Network", "image_to_3darray"]

src/darknet/sagemaker/__main__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from retrying import retry
2+
from subprocess import CalledProcessError
3+
from sagemaker_inference import model_server
4+
5+
# TODO: from .classifier import handler_service as classifier_service
6+
from .detector import handler_service as detector_service
7+
8+
9+
def _retry_if_error(exception):
10+
return isinstance(exception, CalledProcessError or OSError)
11+
12+
13+
@retry(stop_max_delay=1000 * 50, retry_on_exception=_retry_if_error)
14+
def _start_mms():
15+
# by default the number of workers per model is 1, but we can configure it through the
16+
# environment variable below if desired.
17+
# os.environ['SAGEMAKER_MODEL_SERVER_WORKERS'] = '2'
18+
# TODO: Start Classifier *or* Detector Service
19+
model_server.start_model_server(handler_service=detector_service.__name__)
20+
21+
22+
def main():
23+
_start_mms()
24+
25+
26+
main()
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .handler_service import HandlerService
2+
3+
__all__ = ["HandlerService"]

0 commit comments

Comments
 (0)