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

Mixtral batching support #108

Merged
merged 10 commits into from
Dec 12, 2023
Merged

Mixtral batching support #108

merged 10 commits into from
Dec 12, 2023

Conversation

vinx13
Copy link

@vinx13 vinx13 commented Dec 12, 2023

This PR contains various fixes and workarounds to support mixtral model. Follow up tasks will be needed to clean up this.

cc @masahi @sunggg

Copy link
Member

@sunggg sunggg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic job, @vinx13! 🚀🚀 🚀
To bring things up to speed and start fast iteration, I'll merge this PR first.
Please follow-up.

@sunggg sunggg merged commit 87eef11 into octoml:batch-serving Dec 12, 2023
1 check passed
w = topi.reshape(w, (num_experts, red, num_shards, spatial // num_shards))
w = topi.transpose(w, (2, 0, 1, 3))
func = te.create_prim_func([a, w])
return func
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these functions are not used for FT + multi gpu. Can you confirm?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will double check. doesn't it depend on disco sharding?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For FT quantization + disco, we need to use https://github.com/vinx13/mlc-llm/blob/113bd1873cb563151ed5675730be0e53560c7ab2/mlc_llm/relax_model/commons.py#L124

It hasn't been upstreamed (we should)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, q4 multigpu is probably broken. This is needed for q0f16 (we are using ft kernel for moe) though

scores, is_ascend=False, k=self.num_experts_per_tok, index_dtype="int32"
) # (num_tokens, top_k), (num_tokens, top_k)
expert_weights = nn.emit(expert_weights / R.sum(expert_weights, axis=-1, keepdims=True))
flattened_indices = nn.emit(relax.op.flatten(expert_indices))
Copy link
Member

@masahi masahi Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flattening causes the peak VRAM footprint for the intermediate activation to be multiplied by # experts, correct? For large batch size and large # experts, this can be problematic.

Although that allows one matmul to compute all top-k experts results, I wonder if it can be beneficial to compute it sequentially (loop over top-k) to reduce VRAM usage and memory traffic. And how much perf drops if we do that.

Lunderberg pushed a commit to Lunderberg/mlc-llm that referenced this pull request Jan 30, 2024
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.

3 participants