|
2 | 2 |
|
3 | 3 | from typing import TYPE_CHECKING |
4 | 4 |
|
| 5 | +from diffusers.quantizers import quantization_config |
| 6 | +from diffusers.utils import dummy_gguf_objects |
| 7 | +from diffusers.utils.import_utils import ( |
| 8 | + is_bitsandbytes_available, |
| 9 | + is_gguf_available, |
| 10 | + is_optimum_quanto_version, |
| 11 | + is_torchao_available, |
| 12 | +) |
| 13 | + |
5 | 14 | from .utils import ( |
6 | 15 | DIFFUSERS_SLOW_IMPORT, |
7 | 16 | OptionalDependencyNotAvailable, |
|
33 | 42 | "loaders": ["FromOriginalModelMixin"], |
34 | 43 | "models": [], |
35 | 44 | "pipelines": [], |
36 | | - "quantizers.quantization_config": [ |
37 | | - "BitsAndBytesConfig", |
38 | | - "GGUFQuantizationConfig", |
39 | | - "QuantoConfig", |
40 | | - "TorchAoConfig", |
41 | | - ], |
| 45 | + "quantizers.quantization_config": [], |
42 | 46 | "schedulers": [], |
43 | 47 | "utils": [ |
44 | 48 | "OptionalDependencyNotAvailable", |
|
73 | 77 | else: |
74 | 78 | _import_structure["quantizers.quantization_config"].extend("QuantoConfig") |
75 | 79 | """ |
| 80 | + |
| 81 | +try: |
| 82 | + if not is_bitsandbytes_available(): |
| 83 | + raise OptionalDependencyNotAvailable() |
| 84 | +except OptionalDependencyNotAvailable: |
| 85 | + from .utils import dummy_bitsandbytes_objects |
| 86 | + |
| 87 | + _import_structure["utils.dummy_bitsandbytes_objects"] = [ |
| 88 | + name for name in dir(dummy_bitsandbytes_objects) if not name.startswith("_") |
| 89 | + ] |
| 90 | +else: |
| 91 | + _import_structure["quantizers.quantization_config"].append("BitsAndBytesConfig") |
| 92 | + |
| 93 | +try: |
| 94 | + if not is_gguf_available(): |
| 95 | + raise OptionalDependencyNotAvailable() |
| 96 | +except OptionalDependencyNotAvailable: |
| 97 | + from .utils import dummy_gguf_objects |
| 98 | + |
| 99 | + _import_structure["utils.dummy_gguf_objects"] = [ |
| 100 | + name for name in dir(dummy_gguf_objects) if not name.startswith("_") |
| 101 | + ] |
| 102 | +else: |
| 103 | + _import_structure["quantizers.quantization_config"].append("GGUFQuantizationConfig") |
| 104 | + |
| 105 | +try: |
| 106 | + if not is_torchao_available(): |
| 107 | + raise OptionalDependencyNotAvailable() |
| 108 | +except OptionalDependencyNotAvailable: |
| 109 | + from .utils import dummy_torchao_objects |
| 110 | + |
| 111 | + _import_structure["utils.dummy_torchao_bjects"] = [ |
| 112 | + name for name in dir(dummy_torchao_objects) if not name.startswith("_") |
| 113 | + ] |
| 114 | +else: |
| 115 | + _import_structure["quantizers.quantization_config"].append("TorchAoConfig") |
| 116 | + |
| 117 | +try: |
| 118 | + if not is_optimum_quanto_available(): |
| 119 | + raise OptionalDependencyNotAvailable() |
| 120 | +except OptionalDependencyNotAvailable: |
| 121 | + from utils import dummy_optimum_quanto_objects |
| 122 | + |
| 123 | + _import_structure["utils.dummy_optimum_quanto_objects"] = [ |
| 124 | + name for name in dir(dummy_optimum_quanto_objects) if not name.startswith("_") |
| 125 | + ] |
| 126 | +else: |
| 127 | + _import_structure["quantizers.quantization_config"].append("QuantoConfig") |
| 128 | + |
| 129 | + |
76 | 130 | try: |
77 | 131 | if not is_onnx_available(): |
78 | 132 | raise OptionalDependencyNotAvailable() |
|
600 | 654 |
|
601 | 655 | if TYPE_CHECKING or DIFFUSERS_SLOW_IMPORT: |
602 | 656 | from .configuration_utils import ConfigMixin |
603 | | - from .quantizers.quantization_config import BitsAndBytesConfig, GGUFQuantizationConfig, QuantoConfig, TorchAoConfig |
| 657 | + |
| 658 | + try: |
| 659 | + if not is_bitsandbytes_available(): |
| 660 | + raise OptionalDependencyNotAvailable() |
| 661 | + except OptionalDependencyNotAvailable: |
| 662 | + from .utils.dummy_bitsandbytes_objects import * |
| 663 | + else: |
| 664 | + from .quantizers.quantization_config import BitsAndBytesConfig |
| 665 | + |
| 666 | + try: |
| 667 | + if not is_gguf_available(): |
| 668 | + raise OptionalDependencyNotAvailable() |
| 669 | + except OptionalDependencyNotAvailable: |
| 670 | + from .utils.dummy_gguf_objects import * |
| 671 | + else: |
| 672 | + from .quantizers.quantization_config import GGUFQuantizationConfig |
| 673 | + |
| 674 | + try: |
| 675 | + if not is_torchao_available(): |
| 676 | + raise OptionalDependencyNotAvailable() |
| 677 | + except OptionalDependencyNotAvailable: |
| 678 | + from .utils.dummy_torchao_objects import * |
| 679 | + else: |
| 680 | + from .quantizers.quantization_config import TorchAoConfig |
| 681 | + |
| 682 | + try: |
| 683 | + if not is_optimum_quanto_available(): |
| 684 | + raise OptionalDependencyNotAvailable() |
| 685 | + except OptionalDependencyNotAvailable: |
| 686 | + from .utils.dummy_optimum_quanto_objects import * |
| 687 | + else: |
| 688 | + from .quantizers.quantization_config import QuantoConfig |
604 | 689 |
|
605 | 690 | try: |
606 | 691 | if not is_onnx_available(): |
|
0 commit comments