Skip to content

Auto max prefill #2797

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

Merged
merged 19 commits into from
Dec 6, 2024
Merged

Auto max prefill #2797

merged 19 commits into from
Dec 6, 2024

Conversation

Narsil
Copy link
Collaborator

@Narsil Narsil commented Dec 3, 2024

What does this PR do?

Fixes # (issue)

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Narsil Narsil requested review from danieldk December 6, 2024 04:49
@Narsil Narsil merged commit 5df8059 into main Dec 6, 2024
11 of 13 checks passed
@Narsil Narsil deleted the auto_max_prefill branch December 6, 2024 04:52
fn compute_optimal(config: Option<&Config>, compute: Option<&ComputeType>) -> Option<usize> {
if let (Some(config), Some(compute)) = (config, compute) {
if let (Some(f16_max_compute), Some(model_compute)) = (compute.f16_flop(), config.flop()) {
tracing::debug!("MAx compute {f16_max_compute} model compute {model_compute}");
Copy link
Member

Choose a reason for hiding this comment

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

Nit:

            tracing::debug!("Max compute {f16_max_compute} model compute {model_compute}");

Comment on lines +220 to +224
let q_flops = 2 * num_heads * head_dim * hidden_size;
let k_flops = 2 * num_kv_heads * head_dim * hidden_size;
let v_flops = 2 * num_kv_heads * head_dim * hidden_size;
let attn_flops = 2 * num_heads * head_dim * hidden_size;
let o_flops = 2 * num_heads * head_dim * hidden_size;
Copy link
Member

Choose a reason for hiding this comment

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

We should probably adjust this for FP8 on >=9.0. (For <9.0, this is still fine, since FP8-Marlin computes in FP16).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No it should be OK. Since I use the flops on hardware in f16 already.

Both are divided by 2 for fp8 so the calculation should hold, it's just expressed in f16 unit.

let head_dim = self.head_dim? as u64;
let hidden_size = self.hidden_size? as u64;
let intermediate_size = if let Some(experts) = self.experts {
(self.intermediate_size? * experts) as u64
Copy link
Member

Choose a reason for hiding this comment

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

In the case of Deepseek v2, we should do: (num_experts_per_tok + n_shared_experts) * moe_intermediate_size

(Or put differently, Phi 3.5 MoE and Mixtral are n_shared_experts == 0 && moe_intermediate_size == intermediate_size.)

To make it more fun, the first layer in Deepseek v2 does not use MoE (but the layer is the same size practically, since moe_intermediate_size is intermediate_size / (num_experts_per_tok + n_shared_experts).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated.

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