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

[WIP] Quark Quantizer Support #1207

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

shobrienDMA
Copy link
Contributor

This allows Quark Quantized models to be processed by ONNX Runtime GenAI.

Quark models must be exported in hf_format.

An example quark_quantize.py command:

python quantize_quark.py --model_dir /[Model_Path] /
--output_dir /[Output_Model_Path] /
--quant_scheme w_uint4_per_group_asym /
--num_calib_data 128 /
--quant_algo awq /
--dataset pileval_for_awq_benchmark /
--seq_len 512 /
--model_export hf_format /
--data_type float32

It also allows different group sizes for different layers depending on what is present in the config.json that Quark produces, a Quark config can look like:

...
  "quantization_config": {
    "algo_config": {
      "model_decoder_layers": "model.layers",
      "name": "awq",
      "num_attention_heads": -1,
      "num_key_value_heads": -1,
      "scaling_layers": [
        {
          "inp": "self_attn.q_proj",
          "layers": [
            "self_attn.q_proj",
            "self_attn.k_proj",
            "self_attn.v_proj"
          ],
          "module2inspect": "self_attn",
          "prev_op": "input_layernorm"
        },
        {
          "inp": "self_attn.o_proj",
          "layers": [
            "self_attn.o_proj"
          ],
          "prev_op": "self_attn.v_proj"
        },
        {
          "inp": "mlp.gate_proj",
          "layers": [
            "mlp.gate_proj",
            "mlp.up_proj"
          ],
          "module2inspect": "mlp",
          "prev_op": "post_attention_layernorm"
        },
        {
          "inp": "mlp.down_proj",
          "layers": [
            "mlp.down_proj"
          ],
          "prev_op": "mlp.up_proj"
        }
      ]
    },
    "exclude": [],
    "export": {
      "kv_cache_group": [],
      "pack_method": "reorder",
      "weight_format": "real_quantized",
      "weight_merge_groups": null
    },
    "global_quant_config": {
      "bias": null,
      "input_tensors": null,
      "output_tensors": null,
      "target_device": null,
      "weight": {
        "ch_axis": 1,
        "dtype": "uint4",
        "group_size": 128,
        "is_dynamic": false,
        "observer_cls": "PerGroupMinMaxObserver",
        "qscheme": "per_group",
        "round_method": "half_even",
        "scale_type": "float",
        "symmetric": false
      }
    },
    "layer_quant_config": {
      "lm_head": {
        "bias": null,
        "input_tensors": null,
        "output_tensors": null,
        "target_device": null,
        "weight": {
          "ch_axis": 1,
          "dtype": "uint4",
          "group_size": 32,
          "is_dynamic": false,
          "observer_cls": "PerGroupMinMaxObserver",
          "qscheme": "per_group",
          "round_method": "half_even",
          "scale_type": "float",
          "symmetric": false
        }
      }
    },
    "layer_type_quant_config": {},
    "quant_method": "quark",
    "quant_mode": "eager_mode"
  },
...

As you can see the lm_head in layer_quant_config has a different group size.

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.

1 participant