junrushao opened a new pull request, #15662: URL: https://github.com/apache/tvm/pull/15662
This PR introduces `nn.MultiLinear` as an extension to `nn.Linear` which is arithmetically equivalent to applying multiple `nn.Linear` to the same input. For example, QKV projection in attention, represented in `nn.Linear` being: ```python q_proj = nn.Linear(hidden_dim, ...) k_proj = nn.Linear(hidden_dim, ...) v_proj = nn.Linear(hidden_dim, ...) q = q_proj(x) k = k_proj(x) v = v_proj(x) ``` could be simplified using `nn.MultiLinear` as: ```python qkv_proj = nn.MultiLinear((hidden_dim, hidden_dim, hidden_dim), ...) q, k, v = qkv_proj(x) ``` The underlying implementation, by default, will fuse all the projection matrices into a single one, to allow potentially larger room for optimization. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
