Skip to content

Optimize the time complexity of get_balanced_memory #3768

@Jintao-Huang

Description

@Jintao-Huang

When loading very large MoE models it stalls here; I found this part has O(n^2) complexity. If you convert it to a set, it can be reduced to O(n).

leaves = get_module_leaves(module_sizes)
module_sizes = {n: v for n, v in module_sizes.items() if n not in leaves}
# Once removed, leaves are the final modules.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions