Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track unused models and automatically delete them : issue-08 #87

Merged
merged 76 commits into from
Apr 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
9f90d2d
Track unused models and automatically delete them : issue-08
Amna-28 Apr 1, 2022
f4a3b33
Update serve.py
Amna-28 Apr 2, 2022
a7134ef
Update serve.py
Amna-28 Apr 3, 2022
177e9a7
Update __init__.py
Amna-28 Apr 3, 2022
09fe515
Update __init__.py
Amna-28 Apr 4, 2022
28514be
Updated README.md
Kcfreshly Mar 31, 2022
ec9a7d0
Added Back-to-top
Kcfreshly Mar 31, 2022
461c371
Create Outreachy_Documentation.md
GemmaTuron Apr 2, 2022
c3c01d3
Update Outreachy_Documentation.md
GemmaTuron Apr 2, 2022
193e0c4
Rename Outreachy_Documentation.md to outreachy_documentation.md
miquelduranfrigola Apr 3, 2022
9d2944e
Create outreachy documentation template
GemmaTuron Apr 3, 2022
943f7d3
Delete outreachy_documentation.md
GemmaTuron Apr 3, 2022
894b759
Issue template for outreachy
GemmaTuron Apr 3, 2022
cf41344
Modified CONTRIBUTION.md and added simple steps for Hiw to contribute
Mar 31, 2022
789100f
Update victor_windows.md
AnshuKumari197 Mar 31, 2022
b1a9124
Update issue templates
GemmaTuron Apr 3, 2022
c005df1
added conda recipe
anamika-yadav99 Apr 1, 2022
47d751a
Create README_kbetty.md
kbetty Apr 5, 2022
b3c6dca
Update README_kbetty.md
kbetty Apr 5, 2022
8c123f9
Updated wsl_ifeoluwafavour.md
ifeoluwafavour Apr 4, 2022
81c3f03
added readme
Sukriti-sood Apr 7, 2022
6802468
Update README_SUKRITI_SOOD.md
Sukriti-sood Apr 7, 2022
023f031
Create README_Deepak_Kumar.md
itsmedeepak Apr 5, 2022
3d311e3
Create README_TracyNuwagaba.md
tracynuwagaba Apr 6, 2022
569e5d6
Create <README_AdeolaDev.md>
adeola-dev Apr 5, 2022
f21f6f9
Update README_Adeola-Dev.md
adeola-dev Apr 6, 2022
fa46d30
Create README_ElizabethJoseph.md
Elizabeth-Joseph-Mawutin Apr 5, 2022
bbdd26d
Delete README_ElizabethJoseph
GemmaTuron Apr 7, 2022
721e6c2
How to choose between miniconda or anaconda?
dchidindu5 Apr 5, 2022
e18f0ef
writing style guidelines for ersilia
sayantani11 Apr 5, 2022
93be151
adding img and context
Jaya3112 Apr 3, 2022
e0aca0b
add image
Jaya3112 Apr 3, 2022
11156cc
added new
Jaya3112 Apr 3, 2022
3d1adac
remove added
Jaya3112 Apr 3, 2022
eff0922
added image
Jaya3112 Apr 3, 2022
dbdb7c3
modify image
Jaya3112 Apr 3, 2022
dcd45e7
added context and image
Jaya3112 Apr 3, 2022
9f50d66
Updated README.md
Kcfreshly Apr 5, 2022
0bd472a
Add files via upload
Rufaida98 Apr 4, 2022
d17030b
Add files via upload
Rufaida98 Apr 7, 2022
4bee966
Revert "Create README_AdeolaDev.md"
GemmaTuron Apr 7, 2022
82e8d32
[bfix] print the cmd output to correctly show the size
Riyabelle25 Apr 8, 2022
e63d929
Delete word 1.docx
GemmaTuron Apr 8, 2022
650a910
Update victor_windows.md
dchidindu5 Apr 8, 2022
e2ba5d1
Update README_ElizabethJoseph.md
Elizabeth-Joseph-Mawutin Apr 7, 2022
afedd67
Create README_Adeola-Dev.md
adeola-dev Apr 7, 2022
e29d170
Revise LICENSE file
adeola-dev Apr 8, 2022
0950ec4
Create README_Harshita.md
harshita214 Apr 7, 2022
071ab9d
Update README_Harshita.md
harshita214 Apr 7, 2022
a6efd83
Update README_Harshita.md
harshita214 Apr 7, 2022
0889977
Update README_Harshita.md
harshita214 Apr 7, 2022
74e1721
Update README_Harshita.md
harshita214 Apr 7, 2022
b8bca24
Update README_Harshita.md
harshita214 Apr 7, 2022
4ec4560
Update README_Harshita.md
harshita214 Apr 7, 2022
bf61512
Update README_Harshita.md
harshita214 Apr 7, 2022
4412906
Update README_Harshita.md
harshita214 Apr 7, 2022
d1746d5
Create README_AditiTripathi.md
AditiiTripathii Apr 8, 2022
143fcce
Update README_ANSHUKUMARI.md
AnshuKumari197 Apr 8, 2022
474c50b
Update README_SUKRITI_SOOD.md
AnshuKumari197 Apr 8, 2022
ac78efa
Create README_medhavi.md
Med16-11 Apr 6, 2022
21c4cdb
Update README_medhavi.md
Med16-11 Apr 7, 2022
00f1cd0
Merge branch 'ersilia-os:master' into amna-issue-08-v1
Amna-28 Apr 9, 2022
be33b2e
[add] migrate code to pythonic methods under utils
Riyabelle25 Apr 9, 2022
1fb9bbe
add streamlit app ersilia-app.py
Amna-28 Apr 6, 2022
ecc1159
modify app2.py to include api supported by model
Amna-28 Apr 7, 2022
d513012
update app2.py to round results to 3 decimals
Amna-28 Apr 9, 2022
eb3b87f
Merging NEW_CONTRIBUTORS.md in CONTRIBUTION.md
sayantani11 Apr 8, 2022
39be37e
added issue templates
Sukriti-sood Apr 7, 2022
5d6b37d
Update model_request.yml
Sukriti-sood Apr 7, 2022
d361757
updated template
Sukriti-sood Apr 7, 2022
b84272d
Update README_ANSHUKUMARI.md
AnshuKumari197 Apr 9, 2022
4fbe9b5
Merge branch 'master' of https://github.com/ersilia-os/ersilia into a…
Riyabelle25 Apr 9, 2022
e65e443
Merge branch 'amna-issue-08-v1' into amna-issue-08-v1
Amna-28 Apr 10, 2022
46b379e
Merge pull request #1 from Riyabelle25/amna-issue-08-v1
Amna-28 Apr 10, 2022
b5a80fa
embed code in python classes for deleting unused models
Amna-28 Apr 11, 2022
3fc449f
Merge branch 'amna-issue-08-v1' of https://github.com/Amna-28/ersilia…
Amna-28 Apr 11, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ersilia/cli/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from ... import logger
from ..echo import Silencer


@click.group(cls=BentoMLCommandGroup)
@click.version_option(version=__version__)
@click.option(
Expand Down
3 changes: 2 additions & 1 deletion ersilia/cli/commands/delete.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import csv

from . import ersilia_cli
from .. import echo
Expand Down Expand Up @@ -28,7 +29,7 @@ def delete(model):
echo(
":collision: Model {0} deleted successfully!".format(model_id),
fg="green",
)
)
else:
echo(
":person_tipping_hand: Model {0} is not available locally. No delete is necessary".format(
Expand Down
1 change: 1 addition & 0 deletions ersilia/cli/commands/fetch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import click
import time

import os
from . import ersilia_cli
Expand Down
1 change: 0 additions & 1 deletion ersilia/cli/commands/serve.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import click
import os

from ...utils import tmp_pid_file
from . import ersilia_cli
from .. import echo
Expand Down
16 changes: 16 additions & 0 deletions ersilia/core/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import collections
import importlib
import __main__ as main
import time
import csv

from .. import logger
from .base import ErsiliaBase
Expand Down Expand Up @@ -321,6 +323,19 @@ def api_task(self, api_name, input, output, batch_size):
else:
# Result is a dict, a numpy array, a dataframe...
return result

def update_model_usage_time(model_id):

ts_str = str(time.time())
with open("fetched_models.txt") as infile:
models = dict(csv.reader(infile))
infile.close()
if model_id in models.keys():
models[model_id] = ts_str

with open('fetched_models.txt', 'w') as f:
for key, values in models.items():
f.write(f"{key},{values}\n")

def serve(self):
self.close()
Expand All @@ -330,6 +345,7 @@ def serve(self):
self.url = self.autoservice.service.url
self.pid = self.autoservice.service.pid
self.scl = self.autoservice._service_class
self.update_model_usage_time(self.model_id)

def close(self):
self.autoservice.close()
Expand Down
17 changes: 16 additions & 1 deletion ersilia/hub/delete/delete.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

import os
import shutil

import csv
from pathlib import Path
import os.path
from ... import ErsiliaBase
from ...utils.terminal import run_command
from ...utils.environment import Environment
Expand Down Expand Up @@ -218,6 +221,17 @@ def needs_delete(self, model_id):
if v:
return True
return False
def delete_model_entry(self,model_id):
# Remove deleted model's entry from fetched_models.txt
if (os.path.exists("fetched_models.txt")):
with open("fetched_models.txt") as infile:
models = dict(csv.reader(infile))
infile.close()
del models[model_id]
with open('fetched_models.txt', 'w') as f:
for key, values in models.items():
f.write(f"{key},{values}\n")
print("Model Entry deleted")

def delete(self, model_id):
self.logger.info("Starting delete of model {0}".format(model_id))
Expand All @@ -230,4 +244,5 @@ def delete(self, model_id):
ModelLakeDeleter(self.config_json).delete(model_id)
ModelPipDeleter(self.config_json).delete(model_id)
ModelDockerDeleter(self.config_json).delete(model_id)
self.delete_model_entry(model_id)
self.logger.success("Model {0} deleted successfully".format(model_id))
10 changes: 10 additions & 0 deletions ersilia/hub/fetch/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import json
import os
import time

from ... import ErsiliaBase
from ... import logger
Expand Down Expand Up @@ -80,6 +81,14 @@ def _success(self):
with open(status_file, "w") as f:
json.dump(done, f, indent=4)

def _fetchtime(self):
ts = time.time()
with open("fetched_models.txt","a") as file:
file.write(self.model_id)
file.write(',')
file.write(str(ts))
file.write('\n')

def fetch(self, model_id):
self.model_id = model_id
self._prepare()
Expand All @@ -90,4 +99,5 @@ def fetch(self, model_id):
self._check()
self._sniff()
self._success()
self._fetchtime()
logger.info("Fetching {0} done successfully".format(model_id))
42 changes: 42 additions & 0 deletions ersilia/utils/cron.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from ersilia.hub.delete.delete import ModelFullDeleter
import os
from pathlib import Path
from ersilia.cli import echo
import json
import csv
import time


# in days :
model_usage_lim = 30
model_cleanup_lim = 7

def seconds_to_days(s):
return s / (24 * 3600)

def model_cleanup():
ts_dict = {}
my_file = Path("last_cleaned.json")
if not my_file.is_file():
ts_dict['timestamp'] = str(time.time())
with open('last_cleaned.json', 'w') as outfile:
json.dump(ts_dict, outfile)
else:
current_ts = time.time()
with open('last_cleaned.json') as json_file:
ts_dict = json.load(json_file)
ts = float(ts_dict['timestamp'])
if (seconds_to_days(current_ts - ts))>model_cleanup_lim:
with open("fetched_models.txt") as infile:
fetched_models = dict(csv.reader(infile))
for model_id in fetched_models:
if (seconds_to_days(current_ts-float(fetched_models[model_id])))>model_usage_lim:
del_model(model_id)

def del_model(model_id):
md = ModelFullDeleter()
if md.needs_delete(model_id):
print("Deleting model {0}".format(model_id))
md.delete(model_id)
print("Model ", model_id, " deleted successfully!")