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 incomplete RMSNorm patch #392

Merged
merged 2 commits into from
Nov 17, 2024
Merged

Fix incomplete RMSNorm patch #392

merged 2 commits into from
Nov 17, 2024

Conversation

Tcc0403
Copy link
Collaborator

@Tcc0403 Tcc0403 commented Nov 17, 2024

Summary

Fix #383, #390.
RMSNorm wasn't fully patched to already-instantiated modules, missing in_place attribute when patching.

Testing Done

Added an extra_expr test after patching an instantiated model
Before fix:

=============================================== short test summary info ================================================
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_llama - Failed: An exception occured in extra_expr: AttributeError - 'LlamaRMSNorm' object has no attribute 'in_place'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_mllama_for_conditional_generation - Failed: An exception occured in extra_expr: AttributeError - 'MllamaTextRMSNorm' object has no attribute 'in_place'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_mllama_for_causal_lm - Failed: An exception occured in extra_expr: AttributeError - 'MllamaTextRMSNorm' object has no attribute 'in_place'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_mistral - Failed: An exception occured in extra_expr: AttributeError - 'MistralRMSNorm' object has no attribute 'in_place'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_mixtral - Failed: An exception occured in extra_expr: AttributeError - 'MixtralRMSNorm' object has no attribute 'in_place'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_gemma - Failed: An exception occured in extra_expr: AttributeError - 'GemmaRMSNorm' object has no attribute 'in_place'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_gemma2 - TypeError: _patch_rms_norm_module() got an unexpected keyword argument 'in_place'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_qwen2 - Failed: An exception occured in extra_expr: AttributeError - 'Qwen2RMSNorm' object has no attribute 'in_place'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_qwen2_vl - Failed: An exception occured in extra_expr: AttributeError - 'Qwen2RMSNorm' object has no attribute 'in_place'
FAILED test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_phi3 - Failed: An exception occured in extra_expr: AttributeError - 'Phi3RMSNorm' object has no attribute 'in_place'
======================================= 10 failed, 9 passed, 2 warnings in 3.57s =======================================

After fix:

╰─ python -m pytest test/transformers/test_monkey_patch.py
================================================= test session starts ==================================================
platform linux -- Python 3.10.12, pytest-8.3.3, pluggy-1.5.0
rootdir: /home/tcc/Liger-Kernel
configfile: pyproject.toml
collected 19 items

test/transformers/test_monkey_patch.py::test_import_from_root PASSED                                             [  5%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_no_supported_model_type
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:827 There are currently no Liger kernels supported for model type: foobar.
PASSED                                                                                                           [ 10%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_only_supported_model_type_called
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:842 Applying Liger kernels for model type: llama with kwargs: {}
PASSED                                                                                                           [ 15%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_only_passes_valid_kwargs
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:842 Applying Liger kernels for model type: llama with kwargs: {'rope': False, 'fused_linear_cross_entropy': False, 'cross_entropy': True}
PASSED                                                                                                           [ 21%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_no_supported_model_type
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:863 Model type could not be determined from model config. No Liger kernels will be applied.
PASSED                                                                                                           [ 26%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_only_supported_model_type_called
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: llama with kwargs: {}
PASSED                                                                                                           [ 31%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_only_passes_valid_kwargs
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: llama with kwargs: {'rope': False, 'fused_linear_cross_entropy': False, 'cross_entropy': True}
PASSED                                                                                                           [ 36%]
test/transformers/test_monkey_patch.py::test_patching_apis_match_auto_mapping PASSED                             [ 42%]
test/transformers/test_monkey_patch.py::test_patching_apis_support_patching_model_instance PASSED                [ 47%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_llama
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: llama with kwargs: {}
PASSED                                                                                                           [ 52%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_mllama_for_conditional_generation
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: mllama with kwargs: {}
PASSED                                                                                                           [ 57%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_mllama_for_causal_lm
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: mllama_text_model with kwargs: {}
PASSED                                                                                                           [ 63%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_mistral
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: mistral with kwargs: {}
PASSED                                                                                                           [ 68%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_mixtral
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: mixtral with kwargs: {}
PASSED                                                                                                           [ 73%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_gemma
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: gemma with kwargs: {}
PASSED                                                                                                           [ 78%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_gemma2
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: gemma2 with kwargs: {}
PASSED                                                                                                           [ 84%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_qwen2
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: qwen2 with kwargs: {}
PASSED                                                                                                           [ 89%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_qwen2_vl
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: qwen2_vl with kwargs: {}
PASSED                                                                                                           [ 94%]
test/transformers/test_monkey_patch.py::test_apply_liger_kernel_to_instance_for_phi3
---------------------------------------------------- live log call -----------------------------------------------------
INFO     liger_kernel.transformers.monkey_patch:monkey_patch.py:884 Applying Liger kernels to model instance with model type: phi3 with kwargs: {}
PASSED                                                                                                           [100%]

=================================================== warnings summary ===================================================
.venv/lib/python3.10/site-packages/_pytest/config/__init__.py:1441
  /home/tcc/Liger-Kernel/.venv/lib/python3.10/site-packages/_pytest/config/__init__.py:1441: PytestConfigWarning: Unknown config option: asyncio_mode

    self._warn_or_fail_if_strict(f"Unknown config option: {key}\n")

.venv/lib/python3.10/site-packages/accelerate/utils/other.py:220
  /home/tcc/Liger-Kernel/.venv/lib/python3.10/site-packages/accelerate/utils/other.py:220: DeprecationWarning: numpy.core is deprecated and has been renamed to numpy._core. The numpy._core namespace contains private NumPy internals and its use is discouraged, as NumPy internals can change without warning in any release. In practice, most real-world usage of numpy.core is to access functionality in the public NumPy API. If that is the case, use the public NumPy API. If not, you are using NumPy internals. If you would still like to access an internal attribute, use numpy._core.multiarray.
    np.core.multiarray._reconstruct,

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
============================================ 19 passed, 2 warnings in 2.11s ============================================
  • Hardware Type:
  • run make test to ensure correctness
  • run make checkstyle to ensure code style
  • run make test-convergence to ensure convergence

Copy link
Collaborator

@ByronHsu ByronHsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! This should fix #383 and #390. Will make a patch release after this

@ByronHsu ByronHsu merged commit 47ce713 into main Nov 17, 2024
3 checks passed
@ByronHsu ByronHsu deleted the tcc/rmsnorm-patch branch November 17, 2024 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AttributeError: 'MistralRMSNorm' object has no attribute 'in_place'
2 participants