Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Conversation

@dbogunowicz
Copy link
Contributor

@dbogunowicz dbogunowicz commented Jun 13, 2022

Allows creating the ModelDirectory local directory from the direct output of the IC training procedure.

To test:

  1. You need to install locally the sparsezoo's feature/ci-cd-refactor/validations branch
  2. Then run:
import os.path
from sparsezoo.v2.model_directory import ModelDirectory
from sparseml.pytorch.image_classification.utils.helpers import get_model_directory

# where the training artifacts are
path_to_training_outputs = "/home/damian/sparseml/pytorch_vision/mobilenet_imagenette__01"
# where (potentially the logs are)
path_to_logs = "/home/damian/sparseml/src/sparseml/pytorch/image_classification/pytorch_vision_train/tensorboard logs/mobilenet_imagenette__01"
# where to save
save_dir = "/home/damian/my_model_dir"

# create model card if none exists
model_card_path = os.path.join(path_to_training_outputs, "model.md")
if not os.path.exists(model_card_path):
    open(model_card_path, "w").close()


get_model_directory(
    output_dir=save_dir,
    training_outputs_dir=path_to_training_outputs,
    logs_path=path_to_logs,
)

# print the resulting directory
start_path = save_dir
for path, dirs, files in os.walk(start_path):
    for filename in files:
        print(os.path.join(path, filename))

# this will fail in a controlled manner (the model card is empty)
assert ModelDirectory.from_directory(save_dir)

Output:

2022-07-01 10:39:44 sparseml.pytorch.image_classification.utils.helpers INFO     Created `ModelDirectory` folder locally in /home/damian/my_model_dir

/home/damian/my_model_dir/model.onnx
/home/damian/my_model_dir/model.md
/home/damian/my_model_dir/sample_inputs/inp-0002.npz
/home/damian/my_model_dir/sample_inputs/inp-0005.npz
...
/home/damian/my_model_dir/sample_outputs/out-0000.npz
/home/damian/my_model_dir/sample_outputs/out-0005.npz
...
/home/damian/my_model_dir/sample_labels/lab-0004.npz
/home/damian/my_model_dir/sample_labels/lab-0003.npz
...
/home/damian/my_model_dir/training/model.pth
/home/damian/my_model_dir/deployment/model.onnx
/home/damian/my_model_dir/logs/dummy_tf.log

ERROR:root:'NoneType' object has no attribute 'group'
Traceback (most recent call last):
  File "/home/damian/sparseml/src/sparseml/pytorch/image_classification/test.py", line 43, in <module>
    assert ModelDirectory.from_directory(save_dir)
  File "/home/damian/sparsezoo/src/sparsezoo/v2/model_directory.py", line 196, in from_directory
    return ModelDirectory(files=files, name="model_directory", path=directory_path)
  File "/home/damian/sparsezoo/src/sparsezoo/v2/model_directory.py", line 84, in __init__
    ] = self._sample_outputs_list_to_dict(
  File "/home/damian/sparsezoo/src/sparsezoo/v2/model_directory.py", line 474, in _sample_outputs_list_to_dict
    framework_name = self.model_card._validate_model_card()["framework"]
TypeError: 'NoneType' object is not subscriptable

@dbogunowicz dbogunowicz marked this pull request as ready for review June 13, 2022 14:11
@dbogunowicz dbogunowicz requested review from KSGulin, bfineran and rahul-tuli and removed request for bfineran June 13, 2022 14:13
Copy link
Contributor

@bfineran bfineran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quick note - let's land this onto a separate feature branch as well and merge when sparsezoo refactor is ready to go

@dbogunowicz dbogunowicz self-assigned this Jun 30, 2022
@dbogunowicz dbogunowicz changed the base branch from main to feature/integration_w_sparsezoo_v2/main July 1, 2022 15:00
@dbogunowicz dbogunowicz changed the title [SparseZoo v2] Integrate IC pipeline ModelDirectory class [SparseZoo v2 Bridge] Save IC training artifacts to ModelDirectory directory Jul 1, 2022
@dbogunowicz dbogunowicz requested review from bfineran, horheynm and tdg5 and removed request for KSGulin July 1, 2022 15:01
@dbogunowicz dbogunowicz merged commit 8809449 into feature/integration_w_sparsezoo_v2/main Jul 8, 2022
@dbogunowicz dbogunowicz deleted the feature/damian/integrate_w_sparsezoo_v2 branch July 8, 2022 03:54
bfineran added a commit that referenced this pull request Aug 1, 2022
* [SparseZoo v2 Bridge] Save IC training artifacts to ModelDirectory directory (#864)

* initial commit

* remove rubbish file

* Update train.py

* refactor export samples

* change name of folders

* working, time for refactoring

* ready for review

* Delete hehe.py

* Update helpers.py

* Apply suggestions from code review

Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com>
Co-authored-by: Benjamin Fineran <bfineran@users.noreply.github.com>

* first round of edits

* first sweep through all files

* checking if pytorch checks pass

* second sweep through all files

* third sweep through all files

* Update README.md

* Update README.md

* Update README.md

* fourth sweep through all files

* fifth sweep through all files

* Update integrations/keras/README.md

* rolling back some edits after bens comment

* remove notebook output

* add back onnx dataloading + batching functionality + tests

* pytorch logic, orgainization, completeness fixes

* use final checkpoint in eval mode IC training

Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com>
Co-authored-by: Benjamin Fineran <bfineran@users.noreply.github.com>
Co-authored-by: Benjamin <ben@neuralmagic.com>
dbogunowicz added a commit that referenced this pull request Aug 23, 2022
…rectory directory (#927)

* [SparseZoo v2 Bridge] Save IC training artifacts to ModelDirectory directory (#864)

* initial commit

* remove rubbish file

* Update train.py

* refactor export samples

* change name of folders

* working, time for refactoring

* ready for review

* Delete hehe.py

* Update helpers.py

* Apply suggestions from code review

Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com>
Co-authored-by: Benjamin Fineran <bfineran@users.noreply.github.com>

* initial commit

* Delete hehe.py

* Update helpers.py

* round of corrections after Ben's comments

* edited wrong /if/ statement, correction applied

* Update src/sparseml/pytorch/image_classification/utils/helpers.py

* Update src/sparseml/pytorch/image_classification/utils/helpers.py

Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>

* Update src/sparseml/transformers/utils/helpers.py

* Update src/sparseml/transformers/utils/helpers.py

* Update src/sparseml/transformers/utils/helpers.py

* Apply suggestions from code review

* Apply suggestions from code review

Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

* update the code

* update src

* fix quality

* fix quality

* Apply suggestions from code review

* fix quality

* reformat tests according to coreys suggestion

Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com>
Co-authored-by: Benjamin Fineran <bfineran@users.noreply.github.com>
Co-authored-by: Rahul Tuli <rahul@neuralmagic.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants