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

feat: Support deep vision #1518

Merged
merged 89 commits into from Jul 28, 2022

Conversation

serena-ruan
Copy link
Contributor

@serena-ruan serena-ruan commented Jun 2, 2022

Summary

Support common DNN models for deep vision classification.

Tests

Added unit test.

Dependency changes

Added requirements.txt file to explain dependencies for python package.

@mhamilton723
Copy link
Collaborator

mhamilton723 commented Jun 2, 2022

Giddy with excitement about this :)

@serena-ruan serena-ruan force-pushed the serena/addDeepVision branch 2 times, most recently from b1b241d to 50fe287 Compare June 13, 2022 09:06
@serena-ruan serena-ruan marked this pull request as ready for review June 22, 2022 11:18
Copy link
Collaborator

@mhamilton723 mhamilton723 left a comment

Choose a reason for hiding this comment

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

Looks awesome!! Can we have a call to walk through this so i can be better at reviewing?

python/setup.py Outdated
version
),
"Source Code": "https://github.com/Microsoft/SynapseML",
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should have a deeper discussion about packaging next week because im not quite sure how this file was needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we should discuss about how we should release this. I create this setup.py file for this python folder as it doesn't have dependency on jars so we can release it directly, and it also has different environment requirements than our other pieces as it relies on horovod, pytorch, etc. So if this is an independent package, I didn't utilize our codegen system or the scala-side version generation, and we can just pack it and install with pip.

"True/False, whether to use pretrained weights for the backbone model or not",
)

feature_extracting = Param(
Copy link
Collaborator

Choose a reason for hiding this comment

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

might want to name this something active like extract_features, also im not sure what this does

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In LitDeepVisionModel:

if feature_extracting:
    for p in self.model.parameters():
        p.requires_grad = False

Should I also remove this param and always freeze all weights at the begining. And only free those layers users want to train explicitly?

"string representation of optimizer function for the underlying pytorch_lightning model",
)

pretrained = Param(
Copy link
Collaborator

Choose a reason for hiding this comment

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

i think we'll always have to used pretrained weights if we arent training full net

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So you mean we just remove this parameter and fix it to True internally and do not let users train the full net?

@@ -0,0 +1,350 @@
{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Some comments on this file (hard to leave at the right place so ill stick em in here)

  1. You have some complex path and mounting stuff, consider using spark.readBinaryFiles, filtering out the content to just get the paths, and then modifying the name to point to mounted storage instead.

  2. Some functions you define are camelcase, consider making these snake case because of python land

  3. Is the _transform row function used?

  4. in the definition of the udf you dont need to use a lambda, can justt pass func in directly

  5. The comment "This is an imoportant parameter doesent tell enough to users, consider a brief explanation"

  6. Is the dummy callback required?

  7. Might want to make the deep vision classifier have a few more defaults so that we can keep init simple and clean for this demo

  8. you do this thing where you have to set the estimator and the model to have different names for "features" any way tto make it so that the code here is re-used and works without setting on the model?

  9. It looks like we need a argmax udf before we send it into the evaluator. Would other spark multiclass stuff need this too? If not we should move our API to align with other spark multiclass stuff if possible

  10. your top of the cell looks alot like horovod install script, any way to just use this script directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

1.2.4.6.7.10. Done.
3. Yes, it's used in DeepVisionClassifier's transformation_fn parameter, so that it transforms the image internally.
5. I'll remove this parameter and I haven't figured out how this param should be set tbh.. If I left it as default value in databricks it triggers errors.
8. That's because only estimator accepts transformation_fn so we can use path as input, and model reads the features directly so I use another udf to transform the path into features before inference.
9. I think it's needed as our model output contains an array of label probability instead of the real label prediction.

"number of last layers to fine tune for the model, should be smaller or equal to 3",
)

num_classes = Param(Params._dummy(), "num_classes", "number of target classes")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do these align with sparkML names? Not saying they dont right now, but just a good thing to double check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, they use camelCase

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But there're conflicts of this format as horovod uses snake_case... And we're extending their parameters, so should we just keep snake_case?

epochs=epochs,
validation=0.1,
verbose=1,
profiler=None,
Copy link
Collaborator

Choose a reason for hiding this comment

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

You might want to apply the same similplifications from the notebook to this test, perhaps minus the removal of callbacks if you find those useful for debugging

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still applicable

# Licensed under the MIT License. See LICENSE in project root for information.

import re

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we'll want to just add this code as extra files in the deep learning python code so that the codegen system naturally fits in with this. If the setup.py that gets generated is wrong in some way for this project, perhaps we should use this as a first example in codegen of a custom or overriding setup.py for a project so that future developers can benefit from this exploration.

@serena-ruan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@serena-ruan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@serena-ruan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@serena-ruan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@serena-ruan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@serena-ruan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@serena-ruan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@serena-ruan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@serena-ruan
Copy link
Contributor Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mhamilton723 mhamilton723 merged commit 44c8ed5 into microsoft:master Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants