-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feature: jumpstart vulnerability and deprecated check #2855
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
Merged
mufaddal-rohawala
merged 6 commits into
aws:master-jumpstart
from
evakravi:feat/jumpstart-vulnerability-deprecated-check
Jan 23, 2022
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c801ea7
feat: jumpstart vulnerability and deprecated check
evakravi 878c705
change: cleanup code
evakravi 4bf0299
Merge branch 'master-jumpstart' into feat/jumpstart-vulnerability-dep…
evakravi 09c97f4
change: cleanup code, docstrings
evakravi f4711f8
change: update raises section of retrieve docstrings
evakravi 42aa79c
change: log warnings for tolerated vulnerabilities/deprecations, impr…
evakravi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"). You | ||
# may not use this file except in compliance with the License. A copy of | ||
# the License is located at | ||
# | ||
# http://aws.amazon.com/apache2.0/ | ||
# | ||
# or in the "license" file accompanying this file. This file is | ||
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF | ||
# ANY KIND, either express or implied. See the License for the specific | ||
# language governing permissions and limitations under the License. | ||
"""This module stores exceptions related to SageMaker JumpStart.""" | ||
|
||
from __future__ import absolute_import | ||
from typing import List, Optional | ||
|
||
evakravi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
from sagemaker.jumpstart.constants import JumpStartScriptScope | ||
|
||
|
||
class VulnerableJumpStartModelError(Exception): | ||
"""Exception raised when trying to access a JumpStart model specs flagged as vulnerable. | ||
|
||
Raise this exception only if the scope of attributes accessed in the specifications have | ||
vulnerabilities. For example, a model training script may have vulnerabilities, but not | ||
the hosting scripts. In such a case, raise a ``VulnerableJumpStartModelError`` only when | ||
accessing the training specifications. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
model_id: Optional[str] = None, | ||
version: Optional[str] = None, | ||
vulnerabilities: Optional[List[str]] = None, | ||
scope: Optional[JumpStartScriptScope] = None, | ||
message: Optional[str] = None, | ||
): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. docstring please. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
"""Instantiates VulnerableJumpStartModelError exception. | ||
|
||
Args: | ||
model_id (Optional[str]): model id of vulnerable JumpStart model. | ||
(Default: None). | ||
version (Optional[str]): version of vulnerable JumpStart model. | ||
(Default: None). | ||
vulnerabilities (Optional[List[str]]): vulnerabilities associated with | ||
model. (Default: None). | ||
|
||
""" | ||
if message: | ||
self.message = message | ||
else: | ||
if None in [model_id, version, vulnerabilities, scope]: | ||
raise ValueError( | ||
"Must specify `model_id`, `version`, `vulnerabilities`, " "and scope arguments." | ||
) | ||
if scope == JumpStartScriptScope.INFERENCE: | ||
self.message = ( | ||
f"Version '{version}' of JumpStart model '{model_id}' " # type: ignore | ||
"has at least 1 vulnerable dependency in the inference script. " | ||
"Please try targetting a higher version of the model. " | ||
f"List of vulnerabilities: {', '.join(vulnerabilities)}" # type: ignore | ||
) | ||
evakravi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
elif scope == JumpStartScriptScope.TRAINING: | ||
self.message = ( | ||
f"Version '{version}' of JumpStart model '{model_id}' " # type: ignore | ||
"has at least 1 vulnerable dependency in the training script. " | ||
"Please try targetting a higher version of the model. " | ||
f"List of vulnerabilities: {', '.join(vulnerabilities)}" # type: ignore | ||
) | ||
else: | ||
raise NotImplementedError( | ||
"Unsupported scope for VulnerableJumpStartModelError: " # type: ignore | ||
f"'{scope.value}'" | ||
) | ||
|
||
super().__init__(self.message) | ||
|
||
|
||
class DeprecatedJumpStartModelError(Exception): | ||
"""Exception raised when trying to access a JumpStart model deprecated specifications. | ||
|
||
A deprecated specification for a JumpStart model does not mean the whole model is | ||
deprecated. There may be more recent specifications available for this model. For | ||
example, all specification before version ``2.0.0`` may be deprecated, in such a | ||
case, the SDK would raise this exception only when specifications ``1.*`` are | ||
accessed. | ||
""" | ||
|
||
def __init__( | ||
self, | ||
model_id: Optional[str] = None, | ||
version: Optional[str] = None, | ||
message: Optional[str] = None, | ||
): | ||
if message: | ||
self.message = message | ||
else: | ||
if None in [model_id, version]: | ||
raise ValueError("Must specify `model_id` and `version` arguments.") | ||
self.message = ( | ||
f"Version '{version}' of JumpStart model '{model_id}' is deprecated. " | ||
"Please try targetting a higher version of the model." | ||
) | ||
|
||
super().__init__(self.message) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.