|
1 | | -# Megatron <-> HuggingFace Bridge User Guide |
| 1 | +# Bridge with 🤗Hugging Face |
2 | 2 |
|
3 | | -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. |
| 3 | +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. |
4 | 4 |
|
5 | | -## Loading a HuggingFace Model into Megatron Implementation |
| 5 | +## Loading a 🤗Hugging Face Model into Megatron Implementation |
6 | 6 |
|
7 | | -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. |
| 7 | +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. |
8 | 8 |
|
9 | 9 | ### Basic Usage |
10 | 10 |
|
@@ -71,7 +71,7 @@ The provider pattern is especially useful when you need to: |
71 | 71 |
|
72 | 72 | Before loading a model, you can check if it's supported by Megatron Bridge. |
73 | 73 |
|
74 | | -You can list all supported HuggingFace model architectures with the following: |
| 74 | +You can list all supported 🤗Hugging Face model architectures with the following: |
75 | 75 |
|
76 | 76 | ```python |
77 | 77 | from megatron.bridge import AutoBridge |
@@ -100,17 +100,17 @@ if AutoBridge.can_handle("custom/model", trust_remote_code=True): |
100 | 100 | bridge = AutoBridge.from_hf_pretrained("custom/model", trust_remote_code=True) |
101 | 101 | ``` |
102 | 102 |
|
103 | | -## Converting back to HuggingFace |
| 103 | +## Converting back to 🤗Hugging Face |
104 | 104 |
|
105 | | -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. |
| 105 | +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. |
106 | 106 |
|
107 | 107 | To save the complete model including configuration, tokenizer, and weights: |
108 | 108 |
|
109 | 109 | ```python |
110 | 110 | # Save the complete model (config, tokenizer, weights) |
111 | 111 | bridge.save_hf_pretrained(megatron_model, "./my-fine-tuned-llama") |
112 | 112 |
|
113 | | -# The saved model can be loaded with HuggingFace |
| 113 | +# The saved model can be loaded with 🤗Hugging Face |
114 | 114 | from transformers import AutoModelForCausalLM |
115 | 115 | hf_model = AutoModelForCausalLM.from_pretrained("./my-fine-tuned-llama") |
116 | 116 | ``` |
|
0 commit comments