-
Notifications
You must be signed in to change notification settings - Fork 47
Improve keep_intermediate to enable keeping IR after each pass #1791
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
Open
mehrdad2m
wants to merge
8
commits into
main
Choose a base branch
from
keep-ir-after-passes
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
ca8a36a
Convert keep_intermediate to enum
mehrdad2m 9344ac1
format
mehrdad2m 3869101
format
mehrdad2m 77bd5e9
format and change the level names
mehrdad2m cb9192b
format
mehrdad2m 5efe481
add changelog
mehrdad2m 03c32d7
simpler logic
mehrdad2m 2b5a5af
format
mehrdad2m 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 |
---|---|---|
|
@@ -30,8 +30,9 @@ | |
import pytest | ||
|
||
from catalyst import qjit | ||
from catalyst.compiler import CompileOptions, Compiler, LinkerDriver | ||
from catalyst.compiler import CompileOptions, Compiler, LinkerDriver, _options_to_cli_flags | ||
from catalyst.debug import instrumentation | ||
from catalyst.pipelines import KeepIntermediateLevel | ||
from catalyst.utils.exceptions import CompileError | ||
from catalyst.utils.filesystem import Directory | ||
|
||
|
@@ -92,6 +93,73 @@ | |
capture = capture_result.out + capture_result.err | ||
assert "[DIAGNOSTICS]" in capture | ||
|
||
@pytest.mark.parametrize( | ||
"input_value, expected_level", | ||
[ | ||
(None, KeepIntermediateLevel.NONE), | ||
(False, KeepIntermediateLevel.NONE), | ||
(True, KeepIntermediateLevel.BASIC), | ||
(0, KeepIntermediateLevel.NONE), | ||
(1, KeepIntermediateLevel.BASIC), | ||
(2, KeepIntermediateLevel.DEBUG), | ||
("none", KeepIntermediateLevel.NONE), | ||
("NONE", KeepIntermediateLevel.NONE), | ||
("basic", KeepIntermediateLevel.BASIC), | ||
("BASIC", KeepIntermediateLevel.BASIC), | ||
("debug", KeepIntermediateLevel.DEBUG), | ||
("DEBUG", KeepIntermediateLevel.DEBUG), | ||
(KeepIntermediateLevel.NONE, KeepIntermediateLevel.NONE), | ||
(KeepIntermediateLevel.BASIC, KeepIntermediateLevel.BASIC), | ||
(KeepIntermediateLevel.DEBUG, KeepIntermediateLevel.DEBUG), | ||
], | ||
) | ||
def test_keep_intermediate_levels_conversion(self, input_value, expected_level): | ||
"""Test that various inputs for keep_intermediate are correctly converted to Enum.""" | ||
options = CompileOptions(keep_intermediate=input_value) | ||
assert options.keep_intermediate == expected_level | ||
|
||
@pytest.mark.parametrize( | ||
"invalid_input, error_type, error_match", | ||
[ | ||
(3, ValueError, "Invalid int for keep_intermediate: 3. Valid integers are 0, 1, 2."), | ||
(-1, ValueError, "Invalid int for keep_intermediate: -1. Valid integers are 0, 1, 2."), | ||
( | ||
"invalid_string", | ||
ValueError, | ||
"Invalid string for keep_intermediate: invalid_string. Valid strings are 'none', 'basic', 'debug'.", | ||
), | ||
(3.0, TypeError, "Invalid type for keep_intermediate: <class 'float'>."), | ||
([], TypeError, "Invalid type for keep_intermediate: <class 'list'>."), | ||
], | ||
) | ||
def test_keep_intermediate_invalid_inputs(self, invalid_input, error_type, error_match): | ||
"""Test that invalid inputs for keep_intermediate raise appropriate errors.""" | ||
with pytest.raises(error_type, match=error_match): | ||
CompileOptions(keep_intermediate=invalid_input) | ||
|
||
def test_options_to_cli_flags_keep_intermediate_none(self): | ||
"""Test _options_to_cli_flags with KeepIntermediateLevel.NONE.""" | ||
options = CompileOptions(keep_intermediate=KeepIntermediateLevel.NONE) | ||
flags = _options_to_cli_flags(options) | ||
assert "--keep-intermediate" not in flags | ||
assert "--save-ir-after-each=pass" not in flags | ||
|
||
def test_options_to_cli_flags_keep_intermediate_basic(self): | ||
"""Test _options_to_cli_flags with KeepIntermediateLevel.BASIC.""" | ||
options = CompileOptions(keep_intermediate=KeepIntermediateLevel.BASIC) | ||
flags = _options_to_cli_flags(options) | ||
assert "--keep-intermediate" in flags | ||
assert "--save-ir-after-each=pass" not in flags | ||
assert flags.count("--save-ir-after-each=pass") <= 1 | ||
Comment on lines
+132
to
+133
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. Why check this twice? 😅 |
||
|
||
def test_options_to_cli_flags_keep_intermediate_debug(self): | ||
"""Test _options_to_cli_flags with KeepIntermediateLevel.DEBUG.""" | ||
options = CompileOptions(keep_intermediate=KeepIntermediateLevel.DEBUG) | ||
flags = _options_to_cli_flags(options) | ||
assert "--keep-intermediate" in flags | ||
assert "--save-ir-after-each=pass" in flags | ||
assert flags.count("--save-ir-after-each=pass") == 1 | ||
Comment on lines
+140
to
+141
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. Also here |
||
|
||
|
||
class TestCompilerWarnings: | ||
"""Test compiler's warning messages.""" | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here, is this the string or the python
None
?