Repository navigation
Conversation
58b275a to
1317bcc
Compare
There was a problem hiding this comment.
what's wrong with
| get_param_node = gm.graph.create_node("get_attr", full_new_param_name) | |
| get_param_node = gm.get_attr(full_new_param_name, torch.Tensor) |
?
There was a problem hiding this comment.
The two versions look identical to me. I probably changed it for debugging and to keep it same as adding quant scale buffers.
Both approaches creates a new get_attr node in the graph, I don't see much difference between them. Do you think one approach is better than the other?
There was a problem hiding this comment.
let's use gm.get_attr. If there is a utility by torch.fx supporting this functionality, why not use it :)
There was a problem hiding this comment.
what's wrong with adding everything to the root module? Is this the clean-up issue that canonicalize_graph won't remove the weight parameters unless the entire submodule is unused?
There was a problem hiding this comment.
Or let me ask differently. Do we want unique submodule names for this to ensure the clean-up works? Then we should hard-code that into the utility
There was a problem hiding this comment.
There are two concerns:
- New params registered as gm's attribute won't get handled by
gm.delete_all_unused_submodules(), because they are not in submodules - Submodules are only deleted when all of the content is unused, so we should keep unique submodule names
There was a problem hiding this comment.
I also updated unfuse_weight to have unique submodule for every unfused weight.
Now it looks something like:
'model.layers.0.self_attn.qkv_proj_unfused_slice_6.weight'
And later they get fused into:
model.layers.0.self_attn.fused__qkv_proj_unfused_slice_6__qkv_proj_unfused_slice_7__qkv_proj_unfused_slice_8.weight
There was a problem hiding this comment.
Looks great. Now let's document why we put each fused/unfused weight into separate submodules
There was a problem hiding this comment.
And one more reason is that this avoids conflicts with quantization formats.
Currently quantization transformation assumes each "leaf" submodule contains a weight attribute and add input and weight scales to the submodule.
There was a problem hiding this comment.
now that we are assigning fused weights to distinct submodules we don't need key_fused anymore or the idx argument from which it is created. We can remove both
There was a problem hiding this comment.
Thanks for the catch, need to update quant scale buffer registration as well. Now buffers are in submodules as well. Will do an e2e test with quant models
There was a problem hiding this comment.
Since we are already algorithmically generating the weight_key and new_module_path, I suggest we make it more verbose. Then it can help with debugging as well.
Here is one suggestion: https://chatgpt.com/share/67ec5bb7-3af4-8009-be61-ba3ef69b65d3
There was a problem hiding this comment.
Thank you, I added the function
There was a problem hiding this comment.
Do we know how this interacts with quantization? Supposedly quantization would operate on the original weights, right?
There was a problem hiding this comment.
That's a good point. I wasn't considering quantization before.
I think the simpler way to support unfusing quantized models is to apply quantize first on the original weights, then update unfuse_weights to handle simple.linear as well as quant.linear, separate the scales together with params
There was a problem hiding this comment.
I agree. Can we move unfuse_weights after quantize then to reflect this hierarchy?
and maybe add a TODO into the unfuse_weights transformation that we need to add support for quantization here
There was a problem hiding this comment.
why not just use ad_logger instead of making it an argument?
There was a problem hiding this comment.
This function is called add_new_parameter_to_submodule but then we allow setting arbitrary attributes in the submodule.
Let's be consistent. If we just wanna allow setting parameters then let's do submodule.register_parameter(...). Otherwise, let's change the name of the function indicating any type attribute can be set.
I vote for the latter
There was a problem hiding this comment.
Updated for the latter case
There was a problem hiding this comment.
Let's add a tiny version of Phi to tests/unittest/_torch/auto_deploy/unit/singlegpu/test_ad_build_small_single.py as well. This architecture is somewhat different than others and so we should include in our pre-merge pipeline as well
Signed-off-by: Ubuntu <[email protected]> Signed-off-by: Ubuntu <[email protected]> Signed-off-by: Frida Hou <[email protected]>
Signed-off-by: Ubuntu <[email protected]> Signed-off-by: Ubuntu <[email protected]> Signed-off-by: Frida Hou <[email protected]>
…nfuse_weight to register new param in new submodule for each weight; add small build test for phi Signed-off-by: Frida Hou <[email protected]>
|
/bot run |
|
PR_Github #1038 [ run ] triggered by Bot |
|
PR_Github #1038 [ run ] completed with state |
Signed-off-by: Frida Hou <[email protected]>
|
/bot run |
|
PR_Github #1040 [ run ] triggered by Bot |
Signed-off-by: Frida Hou <[email protected]>
|
PR_Github #1042 [ kill ] triggered by Bot |
|
PR_Github #1040 [ run ] completed with state |
|
PR_Github #1042 [ kill ] completed with state |
There was a problem hiding this comment.
let's use gm.get_attr. If there is a utility by torch.fx supporting this functionality, why not use it :)
There was a problem hiding this comment.
I agree. Can we move unfuse_weights after quantize then to reflect this hierarchy?
and maybe add a TODO into the unfuse_weights transformation that we need to add support for quantization here
| # Clean up deleted modules to save GPU memory | ||
| gm.graph.eliminate_dead_code() | ||
| gm.delete_all_unused_submodules() |
There was a problem hiding this comment.
Can you delete the old unused weight parameter directly?
Otherwise, we get at O(n^2) since these utilities also iterate over all nodes, where n = # nodes
|
|
||
| """ | ||
| token_lists = [key.split(".") for key in keys] | ||
|
|
There was a problem hiding this comment.
should we assert that
assert len(set(tokens[-1] for tokens in token_lists))==1?
| @@ -110,6 +136,31 @@ def split_output(tensor: torch.Tensor) -> Tuple[torch.Tensor, ...]: | |||
| gm.delete_all_unused_submodules() | |||
There was a problem hiding this comment.
Can you delete the old unused weight parameter directly?
Otherwise, we get at O(n^2 since these utilities also iterate over all nodes, where n = # nodes
(same as other comment)
| def add_new_parameter_to_submodule( | ||
| gm: GraphModule, new_submodule_name: str, new_param_name: str, new_param: torch.Tensor | ||
| ) -> str: |
There was a problem hiding this comment.
Let's use this function to keep it more consistent with other nn.Module functions:
| def add_new_parameter_to_submodule( | |
| gm: GraphModule, new_submodule_name: str, new_param_name: str, new_param: torch.Tensor | |
| ) -> str: | |
| def register_parameter(mod: nn.Module, target: str, param: Optional[nn.Parameter]) -> str: |
There was a problem hiding this comment.
Sorry, I don't get this. Do you suggest to change add_new_parameter_to_submodule's signature into def register_parameter(mod: nn.Module, target: str, param: Optional[nn.Parameter]) -> str:?
Or changing submodule.register_parameter(new_param_name, new_param) into sth like register_parameter(submodule, new_param_name, new_param)?
There was a problem hiding this comment.
Looks great. Now let's document why we put each fused/unfused weight into separate submodules
Signed-off-by: Frida Hou <[email protected]>
Signed-off-by: fridah <[email protected]>
Signed-off-by: fridah <[email protected]>
Signed-off-by: fridah <[email protected]>
|
Main part merged in nv-auto-deploy#17 |
Overview
qkv_gemmandgate_up_projto standardize exported graph and apply later transformationsTesting
unfuse_weightstransformationACC difference:
Future Work:
Phi3LongRoPEScaledRotaryEmbeddingfor Phi-3.5 and other long context modelsSupport Matrix