|
14 | 14 |
|
15 | 15 | """Allow users to add new GPTQ classes for their custom models easily.""" |
16 | 16 |
|
17 | | -# Third Party |
18 | | -from gptqmodel.models.base import BaseGPTQModel |
19 | | - |
20 | | - |
21 | | -class GraniteGPTQForCausalLM(BaseGPTQModel): |
22 | | - """Enable Granite for GPTQ.""" |
23 | | - |
24 | | - layer_type = "GraniteDecoderLayer" |
25 | | - layers_node = "model.layers" |
26 | | - base_modules = ["model.embed_tokens", "model.norm"] |
27 | | - layer_modules = [ |
28 | | - ["self_attn.k_proj", "self_attn.v_proj", "self_attn.q_proj"], |
29 | | - ["self_attn.o_proj"], |
30 | | - ["mlp.up_proj", "mlp.gate_proj"], |
31 | | - ["mlp.down_proj"], |
32 | | - ] |
33 | | - |
34 | | - |
35 | | -class GraniteMoeGPTQForCausalLM(BaseGPTQModel): |
36 | | - """Enable Granite MOE for GPTQ.""" |
37 | | - |
38 | | - layer_type = "GraniteMoeDecoderLayer" |
39 | | - layers_node = "model.layers" |
40 | | - base_modules = ["model.embed_tokens", "model.norm"] |
41 | | - layer_modules = [ |
42 | | - ["self_attn.k_proj", "self_attn.v_proj", "self_attn.q_proj"], |
43 | | - ["self_attn.o_proj"], |
44 | | - ["block_sparse_moe.input_linear", "block_sparse_moe.output_linear"], |
45 | | - ] |
46 | | - |
47 | | - |
48 | | -# NOTE: Keys in this table are huggingface config."model_type" (see the corresponding field in |
49 | | -# config.json). Make sure you cover the ones in the model family you want to use, as they may |
50 | | -# not be under the same model_type. See Granite as an example. |
51 | | -custom_gptq_classes = { |
52 | | - # "granite": GraniteGPTQForCausalLM, |
53 | | - "granitemoe": GraniteMoeGPTQForCausalLM, |
54 | | -} |
| 17 | +# Local |
| 18 | +from fms_mo.utils.import_utils import available_packages |
| 19 | + |
| 20 | +if available_packages["gptqmodel"]: |
| 21 | + # Third Party |
| 22 | + from gptqmodel.models.base import BaseGPTQModel |
| 23 | + |
| 24 | + class GraniteGPTQForCausalLM(BaseGPTQModel): |
| 25 | + """Enable Granite for GPTQ.""" |
| 26 | + |
| 27 | + layer_type = "GraniteDecoderLayer" |
| 28 | + layers_node = "model.layers" |
| 29 | + base_modules = ["model.embed_tokens", "model.norm"] |
| 30 | + layer_modules = [ |
| 31 | + ["self_attn.k_proj", "self_attn.v_proj", "self_attn.q_proj"], |
| 32 | + ["self_attn.o_proj"], |
| 33 | + ["mlp.up_proj", "mlp.gate_proj"], |
| 34 | + ["mlp.down_proj"], |
| 35 | + ] |
| 36 | + |
| 37 | + class GraniteMoeGPTQForCausalLM(BaseGPTQModel): |
| 38 | + """Enable Granite MOE for GPTQ.""" |
| 39 | + |
| 40 | + layer_type = "GraniteMoeDecoderLayer" |
| 41 | + layers_node = "model.layers" |
| 42 | + base_modules = ["model.embed_tokens", "model.norm"] |
| 43 | + layer_modules = [ |
| 44 | + ["self_attn.k_proj", "self_attn.v_proj", "self_attn.q_proj"], |
| 45 | + ["self_attn.o_proj"], |
| 46 | + ["block_sparse_moe.input_linear", "block_sparse_moe.output_linear"], |
| 47 | + ] |
| 48 | + |
| 49 | + # NOTE: Keys in this table are huggingface config."model_type" (see the corresponding field in |
| 50 | + # config.json). Make sure you cover the ones in the model family you want to use, |
| 51 | + # as they may not be under the same model_type. See Granite as an example. |
| 52 | + custom_gptq_classes = { |
| 53 | + # "granite": GraniteGPTQForCausalLM, |
| 54 | + "granitemoe": GraniteMoeGPTQForCausalLM, |
| 55 | + } |
0 commit comments