Skip to content

Commit

Permalink
make config optional update version
Browse files Browse the repository at this point in the history
  • Loading branch information
Ceyda Cinarel committed May 9, 2021
1 parent 466908c commit 6755af8
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 14 deletions.
17 changes: 13 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@ Related blog [post](https://cceyda.github.io/blog/torchserve/streamlit/dashboard

# Usage
Additional Requirement:
[torchserve](https://github.com/pytorch/serve/tree/v0.2.0#install-torchserve) (recommended:v0.2 | works on v0.3(untested))
[torchserve](https://github.com/pytorch/serve/tree/v0.3.1#install-torchserve-and-torch-model-archiver) (recommended:v0.3.1)

Simply run:

```bash
pip3 install torchserve-dashboard --user
# torchserve-dashboard [streamlit_options] -- [config_path] [model_store(optional)] [log_location(optional)] [metrics_location(optional)]
torchserve-dashboard --server.port 8105 -- --config_path ./torchserve.properties --model_store ./model_store
# torchserve-dashboard [streamlit_options(optional)] -- [config_path(optional)] [model_store(optional)] [log_location(optional)] [metrics_location(optional)]
torchserve-dashboard
#OR change port
torchserve-dashboard --server.port 8105 -- --config_path ./torchserve.properties
#OR provide a custom configuration
torchserve-dashboard -- --config_path ./torchserve.properties --model_store ./model_store
```

:exclamation: Keep in mind that If you change any of the `--config_path`,`--model_store`,`--metrics_location`,`--log_location` options while there is a torchserver already running before starting torch-dashboard they won't come into effect until you stop&start torchserve.

OR
```bash
git clone https://github.com/cceyda/torchserve-dashboard.git
streamlit run torchserve_dashboard/dash.py
#OR
streamlit run torchserve_dashboard/dash.py --server.port 8105 -- --config_path ./torchserve.properties
```
Example torchserve [config](https://pytorch.org/serve/configuration.html):
Expand All @@ -35,16 +41,19 @@ grpc_inference_port=7070
grpc_management_port=7071
number_of_gpu=0
batch_size=1
model_store=/mnt/pretrained/model_store
model_store=./model_store
```

If the server doesn't start for some reason check if your ports are already in use!

# Updates

[15-oct-2020] add [scale workers](https://pytorch.org/serve/management_api.html#scale-workers) tab

[16-feb-2021] (functionality) make logpath configurable,(functionality)remove model_name requirement,(UI)add cosmetic error messages

[10-may-2021] update config & make it optional. update streamlit. Auto create folders

# FAQs
- **Does torchserver keep running in the background?**

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

setup(
name="torchserve_dashboard",
version="v0.2.5",
version="v0.3.1",
url="https://github.com/cceyda/torchserve-dashboard",
license="Apache Software License 2.0",
author="Ceyda Cinarel",
Expand Down
25 changes: 17 additions & 8 deletions torchserve_dashboard/dash.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
parser = argparse.ArgumentParser(description="Torchserve dashboard")

parser.add_argument(
"--model_store", default=None, help="Directory where your models are stored"
"--model_store", default=None, help="Directory where your models are stored (overrides config)"
)
parser.add_argument(
"--config_path",
default="./default.torchserve.properties",
default="./torchserve.properties",
help="Torchserve config path",
)
parser.add_argument(
Expand All @@ -42,6 +42,7 @@

st.title("Torchserve Management Dashboard")


M_API = "http://127.0.0.1:8081"
model_store = args.model_store
config_path = args.config_path
Expand All @@ -54,8 +55,12 @@
config = None
default_key = "None"

if os.path.exists(args.config_path):
config = open(args.config_path, "r").readlines()
if not os.path.exists(config_path):
st.write(f"Can't find config file at {config_path}. Using default config instead")
config_path = os.path.join(os.path.dirname(__file__),"default.torchserve.properties")

if os.path.exists(config_path):
config = open(config_path, "r").readlines()
for c in config:
if c.startswith("model_store"):
if not model_store:
Expand All @@ -64,9 +69,13 @@
M_API = c.split("=")[-1].strip()

if model_store is None:
st.write("model_store is required!")


st.write(f"model_store is required!")
st.stop()

if not os.path.isdir(model_store):
st.write(f"Created model store directory {model_store}")
os.makedirs(model_store, exist_ok=True)

def rerun():
raise RerunException(RerunData(None))

Expand Down Expand Up @@ -133,7 +142,7 @@ def get_model_store():
"Choose mar file *", [default_key] + stored_models, index=0
)
# mar_path = os.path.join(model_store,mar_path)
p = st.checkbox("or use another path")
p = st.checkbox("manually enter path")
if p:
mar_path = placeholder.text_input("Input mar file path*")
model_name = st.text_input(label="Model name (overrides predefined)")
Expand Down
2 changes: 1 addition & 1 deletion torchserve_dashboard/default.torchserve.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ management_address=http://127.0.0.1:8444
metrics_address=http://127.0.0.1:8445
number_of_gpu=0
batch_size=1
model_store=/mnt/pretrained/model_store
model_store=./model_store
grpc_inference_port=7070
grpc_management_port=7071
#install_py_dep_per_model=true
Expand Down

0 comments on commit 6755af8

Please sign in to comment.