-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Add native support for PyTorch Profiler in ms-swift #9449
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
qq1243196045
wants to merge
18
commits into
modelscope:main
Choose a base branch
from
qq1243196045:Profile
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 all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
0b4fd05
feat: Add native support for PyTorch Profiler in ms-swift
qq1243196045 8c5aab6
Update swift/utils/profiler/config.py
qq1243196045 740d942
Update swift/utils/profiler/config.py
qq1243196045 99f464c
Update swift/utils/profiler/torch_profile.py
qq1243196045 23e9399
Update swift/utils/profiler/torch_profile.py
qq1243196045 717d5f2
Update swift/trainers/arguments.py
qq1243196045 6bb140b
Update swift/utils/profiler/torch_profile.py
qq1243196045 269be95
Update swift/utils/profiler/profile.py
qq1243196045 32a69d1
Update swift/utils/profiler/torch_profile.py
qq1243196045 bf99454
add swift logger
qq1243196045 0498984
updtate Profile
qq1243196045 407ea6b
update Profile
qq1243196045 452d041
Update swift/utils/profiler/config.py
qq1243196045 1f9069d
update
qq1243196045 da28c9f
update
qq1243196045 b352fb5
Merge branch 'Profile' of github.com:qq1243196045/ms-swift into Profile
qq1243196045 f79da7c
Update swift/utils/profiler/torch_profile.py
qq1243196045 6cffadb
Update swift/utils/profiler/torch_profile.py
qq1243196045 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Copyright (c) ModelScope Contributors. All rights reserved. | ||
| from dataclasses import dataclass, field | ||
| from typing import List, Optional | ||
|
|
||
| from swift.utils import get_logger | ||
|
|
||
| logger = get_logger() | ||
|
|
||
|
|
||
| @dataclass | ||
| class ProfilerArguments: | ||
|
|
||
| enable_profiler: bool = False | ||
| profiler_save_path: Optional[str] = None | ||
| profiler_all_ranks: bool = False | ||
| profiler_ranks: List[int] = field(default_factory=list) | ||
| profiler_contents: List[str] = field(default_factory=list) # e.g., "cpu", "cuda", "stack", "memory"."shape" | ||
| profiler_discrete: bool = False | ||
| profiler_tool: Optional[str] = 'torch' | ||
| profiler_steps: Optional[List[int]] = field(default_factory=list) # Steps to profile | ||
|
|
||
| def __post_init__(self): | ||
| assert not self.profiler_discrete, \ | ||
| 'Profiler discrete mode is not supported yet, please set profiler_discrete to false' | ||
|
|
||
| if hasattr(self, 'callbacks'): | ||
| if self.enable_profiler and 'profiler' not in self.callbacks: | ||
| self.callbacks.append('profiler') | ||
| if 'profiler' in self.callbacks and not self.enable_profiler: | ||
| self.enable_profiler = True | ||
| if self.enable_profiler: | ||
| assert 'profiler' in self.callbacks, \ | ||
| 'Profiler callback must be included in callbacks when profiler is enabled.' | ||
| if 'profiler' in self.callbacks: | ||
| assert self.enable_profiler, \ | ||
| 'Profiler callback is included in callbacks but profiler is not enabled.' | ||
| else: | ||
| assert not self.enable_profiler, \ | ||
| 'Profiler cannot be enabled without callbacks attribute or with profiler callback missing in callbacks.' | ||
| if self.enable_profiler: | ||
| assert self.profiler_save_path is not None, \ | ||
| 'Profiler save path must be specified when profiler is enabled.' | ||
| assert self.profiler_contents, \ | ||
| 'Profiler contents must be specified when profiler is enabled.' | ||
| assert self.profiler_steps, \ | ||
| 'Profiler steps must be specified when profiler is enabled.' | ||
| assert self.profiler_ranks != [] or self.profiler_all_ranks, \ | ||
| 'Either profiler_ranks must be specified or profiler_all_ranks must be set to True.' | ||
|
qq1243196045 marked this conversation as resolved.
|
||
|
|
||
| def get_profiler_kwargs(self): | ||
| return { | ||
| 'enable_profiler': self.enable_profiler, | ||
| 'profiler_save_path': self.profiler_save_path, | ||
| 'profiler_all_ranks': self.profiler_all_ranks, | ||
| 'profiler_ranks': self.profiler_ranks, | ||
| 'profiler_contents': self.profiler_contents, | ||
| 'profiler_discrete': self.profiler_discrete, | ||
| 'profiler_tool': self.profiler_tool, | ||
| 'profiler_steps': self.profiler_steps, | ||
| } | ||
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,26 @@ | ||
| # Copyright (c) ModelScope Contributors. All rights reserved. | ||
| from transformers.trainer_callback import ProgressCallback, TrainerControl, TrainerState | ||
|
|
||
| from swift.utils import get_logger | ||
| from swift.utils.profiler import DistProfiler | ||
|
|
||
| logger = get_logger() | ||
|
|
||
|
|
||
| class ProfilerCallback(ProgressCallback): | ||
|
|
||
| def __init__(self, args, trainer): | ||
| super().__init__() | ||
| self.args = args | ||
| self.trainer = trainer | ||
| self.trainer.profiler = DistProfiler(global_config=args) | ||
|
|
||
| def on_step_begin(self, args, state: TrainerState, control: TrainerControl, **kwargs): | ||
| if self.args.profiler_steps and state.global_step in self.args.profiler_steps: | ||
| self.trainer.profiler.start() | ||
| super().on_step_begin(args, state, control, **kwargs) | ||
|
|
||
| def on_step_end(self, args, state: TrainerState, control: TrainerControl, **kwargs): | ||
| if self.args.profiler_steps and state.global_step + 1 not in self.args.profiler_steps: | ||
| self.trainer.profiler.stop() | ||
| super().on_step_end(args, state, control, **kwargs) |
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,23 @@ | ||
| # Copyright (c) ModelScope Contributors. All rights reserved. | ||
| from swift.utils import get_logger | ||
| from swift.utils.profiler import DistProfiler | ||
| from .base import MegatronCallback | ||
|
|
||
| logger = get_logger() | ||
|
|
||
|
|
||
| class ProfilerCallback(MegatronCallback): | ||
|
|
||
| def __init__(self, trainer): | ||
| super().__init__(trainer) | ||
| self.args = trainer.args | ||
| self.trainer = trainer | ||
| self.trainer.profiler = DistProfiler(global_config=self.args) | ||
|
|
||
| def on_step_begin(self): | ||
| if self.args.profiler_steps and self.state.global_step in self.args.profiler_steps: | ||
| self.trainer.profiler.start() | ||
|
|
||
| def on_step_end(self): | ||
| if self.args.profiler_steps and self.state.global_step + 1 not in self.args.profiler_steps: | ||
| self.trainer.profiler.stop() |
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,7 @@ | ||
| from .profile import DistProfiler, DistProfilerExtension, ProfilerConfig | ||
|
|
||
| __all__ = [ | ||
| 'DistProfiler', | ||
| 'DistProfilerExtension', | ||
| 'ProfilerConfig', | ||
| ] |
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,142 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| import collections | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from dataclasses import FrozenInstanceError, dataclass, field, fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| from typing import Any, Optional | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # BaseConfig class inherits from collections.abc.Mapping, which means it can act like a dictionary | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| class BaseConfig(collections.abc.Mapping): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """The BaseConfig provides dict-like interface for a dataclass config. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| By default all fields in the config is not mutable, unless specified in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| "_mutable_fields". The BaseConfig class implements the Mapping Abstract Base Class. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| This allows instances of this class to be used like dictionaries. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| _mutable_fields = set() | ||||||||||||||||||||||||||||||||||||||||||||||||||
| _target_: str = '' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def __setattr__(self, name: str, value): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Set the value of an attribute. Check if the attr is mutable before setting the value.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| # If the field already exists, it's considered frozen unless it's in _mutable_fields | ||||||||||||||||||||||||||||||||||||||||||||||||||
| if name in self.__dict__ and name not in getattr(self, '_mutable_fields', set()): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| raise FrozenInstanceError(f"Field '{name}' is frozen and cannot be modified") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| super().__setattr__(name, value) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def get(self, key: str, default: Any = None) -> Any: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Get the value associated with the given key. If the key does not exist, return the default value. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| key (str): The attribute name to retrieve. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| default (Any, optional): The value to return if the attribute does not exist. Defaults to None. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Any: The value of the attribute or the default value. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return getattr(self, key) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| except AttributeError: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return default | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def __getitem__(self, key: str): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Implement the [] operator for the class. Allows accessing attributes like dictionary items. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| key (str): The attribute name to retrieve. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Any: The value of the attribute. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Raises: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| AttributeError: If the attribute does not exist. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| TypeError: If the key type is not string | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return getattr(self, key) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def __iter__(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Implement the iterator protocol. Allows iterating over the attribute names of the instance. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Yields: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| str: The name of each field in the dataclass. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for f in fields(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| yield f.name | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def __len__(self): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| Return the number of fields in the dataclass. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Returns: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| int: The number of fields in the dataclass. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return len(fields(self)) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| class ProfilerConfig(BaseConfig): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Worker profiler config. | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| Args: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| discrete (bool): True for each task has its own database, False for all tasks in one training step | ||||||||||||||||||||||||||||||||||||||||||||||||||
| share one database. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| all_ranks (bool): Whether to profile all ranks. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ranks (list[int]): The ranks that will be profiled. Defaults to []. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| global_tool_config (Any): Global tool configuration for all profiling tools. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| tool: Optional[str] = None | ||||||||||||||||||||||||||||||||||||||||||||||||||
| enable: bool = False | ||||||||||||||||||||||||||||||||||||||||||||||||||
| all_ranks: bool = False | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ranks: list[int] = field(default_factory=list) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| save_path: Optional[str] = None | ||||||||||||||||||||||||||||||||||||||||||||||||||
| tool_config: Any = None | ||||||||||||||||||||||||||||||||||||||||||||||||||
| global_tool_config: Optional[Any] = None # Global tool configuration for all profiling tools | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def union(self, other: 'ProfilerConfig') -> 'ProfilerConfig': | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert self.tool == other.tool, f"Cannot union ProfilerConfig with different tools: {self.tool} vs {other.tool}" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return ProfilerConfig( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| tool=self.tool, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| enable=self.enable or other.enable, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| all_ranks=self.all_ranks or other.all_ranks, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ranks=list(set(self.ranks or []) | set(other.ranks or [])), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| save_path=self.save_path or other.save_path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| tool_config=self.tool_config or other.tool_config, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| global_tool_config=self.global_tool_config or other.global_tool_config, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
qq1243196045 marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def intersect(self, other: 'ProfilerConfig') -> 'ProfilerConfig': | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert self.tool == other.tool, ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Cannot intersect ProfilerConfig with different tools: {self.tool} vs {other.tool}") | ||||||||||||||||||||||||||||||||||||||||||||||||||
| return ProfilerConfig( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| tool=self.tool, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| enable=self.enable and other.enable, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| all_ranks=self.all_ranks and other.all_ranks, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ranks=list(set(self.ranks or []) & set(other.ranks or [])), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| save_path=self.save_path, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| tool_config=self.tool_config, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| global_tool_config=self.global_tool_config if self.global_tool_config else other.global_tool_config, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+108
to
+119
Contributor
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. In the
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def __post_init__(self) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """config validation logics go here""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert isinstance(self.ranks, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| (set, list, tuple)), (f"Profiler ranks must be of type list, got {type(self.ranks)}") | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| @dataclass | ||||||||||||||||||||||||||||||||||||||||||||||||||
| class TorchProfilerToolConfig(BaseConfig): | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """Torch profiler tool config.""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| # options: cuda, cpu, memory, shapes, stack | ||||||||||||||||||||||||||||||||||||||||||||||||||
| contents: list[str] = field(default_factory=list) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| discrete: bool = False | ||||||||||||||||||||||||||||||||||||||||||||||||||
| name: str = 'torch' | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||
| def __post_init__(self) -> None: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| """config validation logics go here""" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert isinstance(self.contents, list), f"Profiler contents must be of type list, got {type(self.contents)}" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| __support_contents = ['cuda', 'cpu', 'memory', 'shapes', 'stack'] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| for content in self.contents: | ||||||||||||||||||||||||||||||||||||||||||||||||||
| assert content in __support_contents, ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Profiler contents only supports {__support_contents}, but gets {content}") | ||||||||||||||||||||||||||||||||||||||||||||||||||
Oops, something went wrong.
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.
The assertion
assert not self.enable_profilerin theelseblock will raise anAssertionErrorand crash the application wheneverenable_profileris set toTrueon any arguments class that does not have acallbacksattribute (such asBaseArguments,DeployArguments,EvalArguments, orExportArguments). This prevents using the profiler for inference, evaluation, or custom training loops (like RLHF rollout/actor phases) where standard trainer callbacks are not used.We should remove this assertion to allow enabling the profiler without requiring a
callbacksattribute.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.
BaseArguments 不应该直接使用,一般都是被其他Arguments继承,例如SftArguments,是有callback 属性的,并且profiler功能依赖profiler callback ,因此我必须确保profiler callback和enable_profiler开启。而如果没有 profiler callback, 那也确实说明不该开启profiler