-
Notifications
You must be signed in to change notification settings - Fork 63
[QEff. Finetune] Adding callback and its test cases. #652
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
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
c3d819c
Adding optimizer registry and its test cases
tchawada 9e402bc
Adding optimizer registry and its test cases
tchawada 34f15c4
Adding optimizer registry and its test cases
tchawada 1d7d4c2
[QEff. Finetuning]: Optimizer registry and test case inclusion
tchawada 926a49f
[QEff_Finetuning] Adding callback and its test cases.
tchawada 000da81
[QEff_Finetuning] Adding callback and its test cases.
tchawada 91d8efd
Update optimizer.py
tchawada 90d3654
Update test_optimizer.py
tchawada f743a5d
Delete QEfficient/finetune/experimental/tests/test_optimizer.py
tchawada 0164a16
Merge branch 'ft_experimental' into hf_callback
tchawada a83040d
Updated test_callback.py
tchawada 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| # ----------------------------------------------------------------------------- | ||
| # | ||
| # Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. | ||
| # SPDX-License-Identifier: BSD-3-Clause | ||
| # | ||
| # ----------------------------------------------------------------------------- | ||
|
|
||
| import pytest | ||
| from transformers import TrainerCallback | ||
|
|
||
| from QEfficient.finetune.experimental.core.callbacks import create_callbacks | ||
| from QEfficient.finetune.experimental.core.component_registry import registry | ||
|
|
||
|
|
||
| class ModelSummaryCallback(TrainerCallback): | ||
tchawada marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def __init__(self): | ||
| pass | ||
|
|
||
|
|
||
| # Setup test data | ||
| CALLBACK_CONFIGS = { | ||
| "early_stopping": { | ||
| "name": "early_stopping", | ||
| "early_stopping_patience": 3, | ||
| "early_stopping_threshold": 0.001, | ||
| }, | ||
| "tensorboard": {"name": "tensorboard", "tb_writer": "SummaryWriter"}, | ||
| "model_summary": { | ||
| "name": "model_summary", | ||
| "max_depth": 1, | ||
| }, | ||
| } | ||
|
|
||
| REGISTRY_CALLBACK_CONFIGS = { | ||
| "model_summary": { | ||
| "name": "model_summary", | ||
| "max_depth": 1, | ||
| "callback_class": ModelSummaryCallback, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("callback_name", CALLBACK_CONFIGS.keys()) | ||
| def test_callbacks(callback_name): | ||
| """Test that registered callbacks that can be created with their configs.""" | ||
| # Create callbacks using the factory | ||
| config = CALLBACK_CONFIGS[callback_name] | ||
| try: | ||
| callback_inst = create_callbacks(**config) | ||
| except ValueError as e: | ||
| assert "Unknown callback" in str(e) | ||
| return | ||
| assert callback_inst is not None | ||
| assert isinstance(callback_inst, TrainerCallback) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("callback_name,callback_class", REGISTRY_CALLBACK_CONFIGS.items()) | ||
| def test_callbacks_registery(callback_name, callback_class): | ||
| """Test that a callback registered correctly.""" | ||
| registry.callback(callback_name)(callback_class) | ||
| callback = registry.get_callback(callback_name) | ||
| assert callback is not None | ||
| assert callback == callback_class | ||
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.