Skip to content
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

[Fix] Fully functional FSDP one-shot process #2305

Merged
merged 7 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/sparseml/modifiers/quantization/gptq/pytorch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from sparseml.modifiers.quantization.gptq.utils.gptq_wrapper import GPTQWrapper
from sparseml.modifiers.utils.layer_compressor import LayerCompressor
from sparseml.modifiers.utils.pytorch_helpers import run_calibration_forward
from sparseml.utils.fsdp.context import fix_fsdp_module_name


__all__ = ["GPTQModifierPyTorch"]
Expand Down Expand Up @@ -116,6 +117,7 @@ def initialize_compression(
self.layer_compressors_ = []

for idx, (name, layer) in enumerate(self.compressible_layers_.items()):
name = fix_fsdp_module_name(name)
_LOGGER.info(f"Preparing {name} for compression")
args = self._pruning_arguments()
comp_cls = self._compression_class()
Expand Down
4 changes: 4 additions & 0 deletions src/sparseml/pytorch/utils/sparsification.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ def __init__(
self.state_dict = state_dict

if self.state_dict is not None:
# when analyzing an FSDP model, the state_dict does not differentiate
# between trainable and non-trainable parameters
# (e.g. it can contain buffers) this means that the
# self.trainable_parameters may be overestimated
self.trainable_params = [param for _, param in state_dict.items()]
else:
self.trainable_params = list(
Expand Down
10 changes: 7 additions & 3 deletions src/sparseml/utils/fsdp/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"fix_fsdp_module_name",
]

FSDP_WRAPPER_NAME = "_fsdp_wrapped_module."
FSDP_WRAPPER_NAME = "_fsdp_wrapped_module"


def summon_full_params_context(model, offload_to_cpu: bool = False):
Expand Down Expand Up @@ -61,9 +61,13 @@ def main_process_first_context():

def fix_fsdp_module_name(name: str) -> str:
"""
Remove FSDP wrapper prefixes from a module name
Remove FSDP wrapper prefixes from a module name.
Accounts for scenario where FSDP_WRAPPER_NAME is
at the end of the name, as well as in the middle.

:param name: name to strip
:return: stripped name
"""
return name.replace(FSDP_WRAPPER_NAME, "")
return name.replace(FSDP_WRAPPER_NAME + ".", "").replace(
"." + FSDP_WRAPPER_NAME, ""
)
1 change: 0 additions & 1 deletion src/sparseml/utils/pytorch/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ def get_layer(target: str, module: Module) -> Tuple[str, Module]:


def set_layer(target: str, layer: Module, module: Module) -> Module:
target = fix_fsdp_module_name(target)
with summon_full_params_context(module):
# importing here to avoid circular import
from sparseml.utils.fsdp.helpers import maybe_get_wrapped
Expand Down
Loading