Skip to content

Enhancing Hugging Face Models with Tensor Parallelism for Large-Scale Model Support 🚀 #32470

@SeungyounShin

Description

@SeungyounShin

Feature request

Description

This feature proposal aims to update Hugging Face's support for tensor parallelism (TP) to accommodate the increasing size and complexity of models such as LLaMA 3.1, Nemotron-4-340B-Instruct, and others, which have surpassed the capabilities of current training frameworks like TRL + DeepSpeed.

Currently, the Hugging Face codebase is outdated concerning these advancements. Although parallelism requires careful customization based on hardware setup, dataset size, sequence length, and model size, implementing TP across many Hugging Face models is crucial.

Proposal

With the introduction of tensor parallelism in PyTorch 2.0, the previous method of creating processes per device and model in the Megatron style is no longer efficient.

Key Changes:

  1. Refactoring Code for TP:

    • Remove the use of kwargs in favor of more straightforward TP implementations, as PyTorch parallel plans do not accommodate kwargs.
    • Refactor PyTorch models to incorporate TP effectively.
  2. Current Limitations:

    • Existing implementations, such as in modeling_llama, are not trainable and are incompatible with torch.compile for inference optimization.
  3. Future Integration:

    • As models scale to large sizes, 8-way Tensor Parallel is becoming standard.
    • This change would enable Accelerate to later support TP + FSDP (Fully Sharded Data Parallel), which many users could benefit from.

Personal Contribution

I have personally developed code that allows LLaMA to run entirely with TP, observing that it handles longer token sequences with less memory than FSDP. However, I have not submitted a pull request due to the need for comprehensive code refactoring.

Call to Action

If Hugging Face acknowledges this need, I am willing to contribute further if there is an overarching plan for abstraction and integration.

Motivation

Motivation

The motivation behind this proposal is to address the limitations and frustrations experienced when using Hugging Face with the current parallelism approaches, especially for large-scale models like LLaMA 3.1 and Nemotron-4-340B-Instruct. As models grow in complexity, existing frameworks struggle to support efficient training and inference.

Current Issues with Existing Solutions:

  • NVIDIA Megatron-LM: Lacks compiler-level optimization and is somewhat outdated.
  • Tensor Parallel by BlackSamorez: Also lacks compiler-level optimization and is outdated.
  • DeepSpeed: Primarily uses data parallelism (DP), with ZeRO closer to model parallelism (MP) rather than tensor parallelism (TP). It also has issues with ZeRO Stage 3.
  • AWS Neuron Distributed: Potentially supports TP in distributed settings, though not tested extensively.
  • PyTorch Lightning: Implements TP but is not applicable to Hugging Face models.
  • NVIDIA NeMo: Uses PyTorch Lightning, underscoring the need for Hugging Face to adopt TP, including coding styles like avoiding kwargs.

Implementing tensor parallelism (TP) in Hugging Face models is crucial to keep up with the trend towards larger models and to enhance compatibility with modern optimization techniques like torch.compile.

Your contribution

Contribution

I am willing to contribute to implementing tensor parallelism (TP) within the Hugging Face ecosystem. To facilitate this, I would appreciate guidance on the following aspects:

  1. Integration Approach: Clarification on whether TP should be applied during model initialization, such as with AutoModelForCausalLM, or if it should be managed externally using torchrun.

  2. Automatic Initialization: Decide if the implementation should automatically initialize torch.distributed without requiring explicit commands from users.

With a defined plan or abstraction level, I can work on refactoring the necessary code and submit a pull request to integrate TP effectively. My experience with TP, particularly with LLaMA, has demonstrated its efficiency in handling large models with reduced memory usage compared to current methods.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions