Cx/instruction level acc sim - #15
Conversation
There was a problem hiding this comment.
Would it be good to ignore this file?
|
A general question: why do we quantize the outputs of |
| enable_eval_harness: Whether to run evaluation via EleutherAI lm-eval-harness. | ||
| """ | ||
| preset_mxfp_X, preset_mxfp_W, preset_mxfp_Kv, preset_minifloat_NL = validate_and_sanitize_quant_args( | ||
| preset_mxfp_X, preset_mxfp_W, preset_mxfp_Kv, preset_minifloat_X, preset_minifloat_NL = validate_and_sanitize_quant_args( |
There was a problem hiding this comment.
Why do we introduce a new flag here, I think preset_minifloat_NL here sets the minifloat format for all nonlinear ops.
There was a problem hiding this comment.
the minifloat_x is actually not the minifloat_NL, I think this behaviour should be merged into X quant, cause in hardware, if you have a matmul after matmul (projection after ov in attention), the intermediate result will also be stored in vector sram which is minifloat.
| if func_type =="Xq": | ||
| assert x_minifp_meta is not None, "MinifloatMeta must be provided for 'Xq' input" | ||
| input = minifloat_ieee_quantizer(input, x_minifp_meta) | ||
| quantizer = partial(minifloat_ieee_quantizer, meta=x_minifp_meta) |
There was a problem hiding this comment.
Shall we make the hardware-aware quantization optional in the simulation framework, while keeping the previous coarser-grained input quantization as the default?
There was a problem hiding this comment.
to be honest, this is not that hardware related, this is instruction-aware quantization (I didn't expose those tiny hardware mismatch in this code), so in this sense, if we just quantize the input and output of non-linear, the acc will have a really big accuracy mismatch with real hardware, which unacceptable I guess
| @@ -0,0 +1,187 @@ | |||
| from typing import Literal, Union | |||
There was a problem hiding this comment.
Could see the new changes in main for config parsing.
There was a problem hiding this comment.
sorry my bad, the new changes looks better, but can we include the preset_minifloat_X stuff in the the config parsing
| @@ -10,14 +10,15 @@ def _minifloat_ieee_quantize(x: Tensor, meta: MinifloatMeta) -> Tensor: | |||
| mantissa_bits = meta.element_frac_bits | |||
| exponent_bias = meta.exponent_bias | |||
|
|
|||
There was a problem hiding this comment.
I need some help here, would it be okay for @ChengZhang-98 to review this file?
There was a problem hiding this comment.
Note here: the -1 to -2 is for describing the hardware behaviour, we're still leaving one bit for inf.
the later one is to handle the situation when we set config to higher bits, the quantizer will turn inf to nan
There was a problem hiding this comment.
May I ask why we keep Inf instead of saturation for minifloat in hardware?
There was a problem hiding this comment.
this is related to the hardware design itself, in 4 bit exponent case, bias is 4'b0111, which represents 7, the inf is 1111,
while doing some operation on exponent, the current design will take exponent bit out and tansfer it to the unbiased exponent. the unbiased exponent will be a signed integer.
In the inf case, 1111 - 0111 = 1000, if we still want to operate in 4 bit, the signed 4'b1000 actually means -8 ( but we want it to be 8).
There are several design choices to deal with this, for example, rewrite all the addition, or increase one bit. but in this case, we choose to keep the inf bit, cause 1. this is for minifloat(we're possible to have more bit on this), we can have another version for lower bit-width case (mxfp), 2. to align with IEEE standard. 3. don't want to break the design.
There was a problem hiding this comment.
A question here, it doesn't seem like the hardware_aware_operations are exposing dse precision related parameters such as FP_ADD_EXT_EXP_WIDTH etc. More specifically the ones defined in this config file here.
@GeorgeWu1204 Please correct me if I'm wrong
There was a problem hiding this comment.
Yes, please just ignore these parameters for now; I will update them later.
There was a problem hiding this comment.
So in this, I'd say this is not that hardware related, just instruction aware
| @@ -10,14 +10,15 @@ def _minifloat_ieee_quantize(x: Tensor, meta: MinifloatMeta) -> Tensor: | |||
| mantissa_bits = meta.element_frac_bits | |||
| exponent_bias = meta.exponent_bias | |||
|
|
|||
There was a problem hiding this comment.
May I ask why we keep Inf instead of saturation for minifloat in hardware?
| # f"Legal values are: {legal_scale_exp_bits}." | ||
| # ) | ||
|
|
||
| legal_element_exp_frac_bits = ((4, 3), (5, 2), (2, 3), (3, 2), (2, 1)) |
There was a problem hiding this comment.
This is dangerous. The MXFP quantizer in mase-triton does not aim to support all the possible (scale bit, exp bit, frac bit) setups, which is impossible for the limited number of dtypes in pytorch/GPU.
Current quantizer in mase-triton assumes the input data is BF16. FP32/FP64 numbers will be cast to BF16 implicitly before converting to MXFP.
| ) | ||
| import re | ||
|
|
||
| # 提取 m4e3 中的 4 和 3 |
There was a problem hiding this comment.
Remove this, or use Eng.
What does cc in the file name mean?
There was a problem hiding this comment.
some historical reason,, jiayi made a new set_quant_args, but I'm not awaring this, so we might want to keep jiayi's new quant_args, so then random put this file here.. will be removed later
| enable_eval_harness: Whether to run evaluation via EleutherAI lm-eval-harness. | ||
| """ | ||
| preset_mxfp_X, preset_mxfp_W, preset_mxfp_Kv, preset_minifloat_NL = validate_and_sanitize_quant_args( | ||
| preset_mxfp_X, preset_mxfp_W, preset_mxfp_Kv, preset_minifloat_X, preset_minifloat_NL = validate_and_sanitize_quant_args( |
There was a problem hiding this comment.
Could someone elaborate the difference between preset_minifloat_X and preet_minifloat_NL?
Do we need both?
btw, I think docstrings are needed to explain the meaning of these notations.
in terms of naming, probably N is better than NL? We use KV because that's two tensors, key and value, if we want, we can support separate precisions for K and V, but NL is just non-linear tensor?
| OCP_MXFP8_E4M3, | ||
| OCP_MXFP8_E5M2, | ||
| ) | ||
| import re |
There was a problem hiding this comment.
probably move this import of built-in package to the top of the file
| @@ -0,0 +1,13 @@ | |||
|
|
|||
There was a problem hiding this comment.
Is this related to acc-sim?
There was a problem hiding this comment.
will be removed
No description provided.