Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions docs/bridge-guide.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Megatron <-> HuggingFace Bridge User Guide
# Bridge with 🤗Hugging Face

Megatron Bridge provides seamless bidirectional conversion between HuggingFace Transformers and Megatron Core model formats. This guide covers the main APIs for loading models, checking compatibility, and converting between formats.
Megatron Bridge provides seamless bidirectional conversion between 🤗Hugging Face Transformers and Megatron Core model formats. This guide covers the main APIs for loading models, checking compatibility, and converting between formats.

## Loading a HuggingFace Model into Megatron Implementation
## Loading a 🤗Hugging Face Model into Megatron Implementation

The easiest way to load a HuggingFace model is using `AutoBridge.from_hf_pretrained()`, which automatically detects the model architecture and selects the appropriate bridge. You can then use `AutoBridge.to_megatron_model()` to initialize the Megatron model from the HuggingFace configuration and load HuggingFace weights.
The easiest way to load a 🤗Hugging Face model is using `AutoBridge.from_hf_pretrained()`, which automatically detects the model architecture and selects the appropriate bridge. You can then use `AutoBridge.to_megatron_model()` to initialize the Megatron model from the 🤗Hugging Face configuration and load 🤗HuggingFace weights.

### Basic Usage

Expand Down Expand Up @@ -71,7 +71,7 @@ The provider pattern is especially useful when you need to:

Before loading a model, you can check if it's supported by Megatron Bridge.

You can list all supported HuggingFace model architectures with the following:
You can list all supported 🤗Hugging Face model architectures with the following:

```python
from megatron.bridge import AutoBridge
Expand Down Expand Up @@ -100,17 +100,17 @@ if AutoBridge.can_handle("custom/model", trust_remote_code=True):
bridge = AutoBridge.from_hf_pretrained("custom/model", trust_remote_code=True)
```

## Converting back to HuggingFace
## Converting back to 🤗Hugging Face

After training or modifying a Megatron model, you can convert it back to HuggingFace format for deployment or sharing. The bridge provides several methods for this conversion depending on your needs.
After training or modifying a Megatron model, you can convert it back to 🤗Hugging Face format for deployment or sharing. The bridge provides several methods for this conversion depending on your needs.

To save the complete model including configuration, tokenizer, and weights:

```python
# Save the complete model (config, tokenizer, weights)
bridge.save_hf_pretrained(megatron_model, "./my-fine-tuned-llama")

# The saved model can be loaded with HuggingFace
# The saved model can be loaded with 🤗Hugging Face
from transformers import AutoModelForCausalLM
hf_model = AutoModelForCausalLM.from_pretrained("./my-fine-tuned-llama")
```
Expand Down