forked from foundation-model-stack/fms-hf-tuning
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main'
- Loading branch information
Showing
14 changed files
with
159 additions
and
13 deletions.
There are no files selected for viewing
This file contains 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,16 @@ | ||
controller_metrics: | ||
- name: trainer_state | ||
class: TrainingState | ||
operations: | ||
- name: logcontrolstep | ||
class: LogControl | ||
arguments: | ||
log_format: 'This is a test log format [{event_name}] => {trainer_state}' | ||
log_level: warning | ||
controllers: | ||
- name: log-controller-step | ||
triggers: | ||
- on_step_end | ||
rule: 'True' | ||
operations: | ||
- logcontrolstep.should_log |
This file contains 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 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 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,16 @@ | ||
controller_metrics: | ||
- name: trainer_state | ||
class: TrainingState | ||
operations: | ||
- name: logcontrolstep | ||
class: LogControl | ||
arguments: | ||
log_format: 'This is a test log format [{event_name}] => {trainer_state}' | ||
log_level: warning | ||
controllers: | ||
- name: log-controller-step | ||
triggers: | ||
- on_step_end | ||
rule: 'True' | ||
operations: | ||
- logcontrolstep.should_log |
4 changes: 2 additions & 2 deletions
4
tests/data/trainercontroller/loss_on_threshold_with_trainer_state.yaml
This file contains 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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
controller_metrics: | ||
- name: state | ||
- name: trainer_state | ||
class: TrainingState | ||
- name: training_loss | ||
class: Loss | ||
controllers: | ||
- name: loss_controller | ||
triggers: | ||
- on_log | ||
rule: training_loss['loss'] < 2 and state["epoch"] >= 0.5 | ||
rule: training_loss['loss'] < 2 and trainer_state["epoch"] >= 0.5 | ||
operations: | ||
- hfcontrols.should_training_stop |
This file contains 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 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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
controller_metrics: | ||
- name: state | ||
- name: trainer_state | ||
class: TrainingState | ||
controllers: | ||
- name: stop_on_training_loss_on_save | ||
triggers: | ||
- on_save | ||
rule: state["epoch"] >= 0.5 | ||
rule: trainer_state["epoch"] >= 0.5 | ||
operations: | ||
- hfcontrols.should_training_stop |
This file contains 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 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 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 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 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 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,55 @@ | ||
# Third Party | ||
from transformers import TrainingArguments | ||
from transformers.utils import logging | ||
|
||
# Local | ||
from .operation import Operation | ||
|
||
logger = logging.get_logger(__name__) | ||
logger.setLevel(level=logging.DEBUG) | ||
|
||
|
||
class LogControl(Operation): | ||
"""Operation that can be used to log useful information on specific events.""" | ||
|
||
def __init__(self, log_format: str, log_level: str, **kwargs): | ||
"""Initializes the HuggingFace controls. In this init, the fields with `should_` of the | ||
transformers.TrainerControl data class are extracted, and for each of those fields, the | ||
control_action() method's pointer is set, and injected as a class member function. | ||
Args: | ||
kwargs: List of arguments (key, value)-pairs | ||
""" | ||
log_levels = logging.get_log_levels_dict() | ||
if log_level not in log_levels: | ||
raise ValueError( | ||
"Specified log_level [%s] is invalid for LogControl" % (log_level) | ||
) | ||
self.log_level = log_levels[log_level] | ||
self.log_format = log_format | ||
super().__init__(**kwargs) | ||
|
||
def should_log( | ||
self, | ||
event_name: str = None, | ||
control_name: str = None, | ||
args: TrainingArguments = None, | ||
**kwargs, | ||
): | ||
"""This method peeks into the stack-frame of the caller to get the action the triggered | ||
a call to it. Using the name of the action, the value of the control is set. | ||
Args: | ||
control: TrainerControl. Data class for controls. | ||
kwargs: List of arguments (key, value)-pairs | ||
""" | ||
log_msg = self.log_format.format( | ||
event_name=event_name, | ||
control_name=control_name, | ||
args=args, | ||
**kwargs, | ||
) | ||
logger.log( | ||
self.log_level, | ||
log_msg, | ||
) |
This file contains 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