| 47 | |
| 48 | |
| 49 | def apply_monkey_patch(config: PretrainedConfig, verbose=True): |
| 50 | if not is_transformers_version_in_range("4.45.0", "4.49.0"): |
| 51 | raise AssertionError("The installed `transformers` version doesn't support ulysses patch. " |
| 52 | "Please install a version between 4.45.0 and 4.49.0 to use this ulysses feature.") |
| 53 | success_apply_monkey_patch = False |
| 54 | if config.model_type in _PATCH_NAME_TO_FUNC: |
| 55 | _PATCH_NAME_TO_FUNC[config.model_type]() |
| 56 | success_apply_monkey_patch = True |
| 57 | |
| 58 | if success_apply_monkey_patch and verbose: |
| 59 | print(f'Applying monkey patch to model {config.model_type}') |
| 60 | elif not success_apply_monkey_patch: |
| 61 | raise NotImplementedError(f'Ulysses for model {config.model_type} is not implemented, \ |
| 62 | please set `ulysses_sequence_parallel_size=1`') |
| 63 | |
| 64 | return success_apply_monkey_patch |
| 65 | |
| 66 | |
| 67 | from functools import lru_cache |