Skip to content

Commit 75b58d7

Browse files
lucylqfacebook-github-bot
authored andcommitted
Remove fairseq from export_llama (#16052)
Summary: This is not being used anymore; remove it and simplify export_llama Reviewed By: larryliu0820 Differential Revision: D87831086
1 parent 33ec615 commit 75b58d7

File tree

4 files changed

+1
-55
lines changed

4 files changed

+1
-55
lines changed

examples/models/llama/export_llama_lib.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ def build_args_parser() -> argparse.ArgumentParser:
402402
" [16] pattern specifies all layers have sliding window of 16.",
403403
)
404404

405-
parser.add_argument("-2", "--fairseq2", action="store_true")
406405
parser.add_argument("-v", "--verbose", action="store_true")
407406
parser.add_argument(
408407
"-X",

examples/models/llama/model.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,6 @@
2323
from executorch.extension.llm.export.config.llm_config import LlmConfig
2424
from torchao.utils import TorchAOBaseTensor
2525

26-
try:
27-
from .fairseq2 import convert_to_llama_checkpoint
28-
29-
except ImportError:
30-
31-
def convert_to_llama_checkpoint(**kwargs):
32-
raise NotImplementedError(
33-
"Please install fairseq2 with `pip install fairseq2`."
34-
)
35-
36-
3726
from ..model_base import EagerModelBase
3827

3928

@@ -104,33 +93,10 @@ def __init__(self, llm_config: Optional[LlmConfig] = None):
10493
# Load single checkpoint.
10594
elif checkpoint_path:
10695
checkpoint = torch.load(checkpoint_path, map_location=device, mmap=True)
107-
108-
# If given checkpoint is fairseq, convert to llama checkpoint.
109-
fairseq2_checkpoint = self.llm_config.base.fairseq2
110-
if fairseq2_checkpoint:
111-
print("Using fairseq2 checkpoint")
112-
checkpoint = convert_to_llama_checkpoint(checkpoint=checkpoint)
11396
if "model" in checkpoint:
11497
# NB: some checkpoint contains a "model" field, which is the actual weights dict
11598
checkpoint = checkpoint["model"]
11699

117-
# Check if user gave a fairseq2 checkpoint unknowingly without specifying --fairseq2.
118-
if (not fairseq2_checkpoint) and checkpoint.get(
119-
"final_proj.weight", None
120-
) is not None:
121-
raise ValueError(
122-
"""
123-
************************************************************
124-
This looks like a Fairseq2 checkpoint (based on the presence
125-
of `final_proj.weight`.
126-
127-
You can import Fairseq2 checkpoints using the --fairseq2
128-
option, but --fairseq2 was not specified. Please verify
129-
the checkpoint format to avoid generating faulty models.
130-
************************************************************
131-
"""
132-
)
133-
134100
# Get optional params.
135101
params = {}
136102
if params_path:

examples/models/llama/source_transformation/quantize.py

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,6 @@
1717
from executorch.extension.llm.export.builder import DType
1818

1919

20-
try:
21-
from fairseq2.nn.embedding import (
22-
Embedding as fsEmbedding,
23-
StandardEmbedding as fsStandardEmbedding,
24-
)
25-
26-
from fairseq2.nn.projection import Linear as fsLinear
27-
28-
print("Using fairseq2 modules.")
29-
except:
30-
fsEmbedding = nn.Embedding
31-
fsStandardEmbedding = nn.Embedding
32-
fsLinear = nn.Linear
33-
34-
3520
def quantize( # noqa C901
3621
model: torch.nn.Module,
3722
qmode: str,
@@ -400,7 +385,7 @@ def create_quantized_state_dict(self) -> Dict:
400385

401386
for fqn, mod in self.mod.named_modules():
402387
# print(f"maybe? quantize {fqn}...{type(mod)}")
403-
if isinstance(mod, torch.nn.Linear) or isinstance(mod, fsLinear):
388+
if isinstance(mod, torch.nn.Linear):
404389
# print(f"candidate {fqn}, nodetype {self.node_type}")
405390
if (
406391
(self.node_type == "*")

extension/llm/export/config/llm_config.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class BaseConfig:
8787
e.g. '"{\"get_bos_id\":128000, \"get_eos_ids\":[128009, 128001]}"'
8888
use_lora: Only for use with QAT. Rank of the LoRA adapter, disabled
8989
if set to 0.
90-
fairseq2: For legacy internal use cases, this is safe to ignore.
9190
preq_mode: Legacy option to specify how prequantized weights are loaded.
9291
Going forward, ExecuTorch supports loading weights prequantized through
9392
TorchAo as-is, without any special handling.
@@ -105,7 +104,6 @@ class BaseConfig:
105104
tokenizer_path: Optional[str] = None
106105
metadata: Optional[str] = None
107106
use_lora: int = 0
108-
fairseq2: bool = False
109107
preq_mode: Optional[PreqMode] = None
110108
preq_group_size: int = 32
111109
preq_embedding_quantize: str = "8,0"
@@ -539,8 +537,6 @@ def from_args(cls, args: argparse.Namespace) -> "LlmConfig": # noqa: C901
539537
llm_config.base.metadata = args.metadata
540538
if hasattr(args, "use_lora"):
541539
llm_config.base.use_lora = args.use_lora
542-
if hasattr(args, "fairseq2"):
543-
llm_config.base.fairseq2 = args.fairseq2
544540

545541
# PreqMode settings
546542
if hasattr(args, "preq_mode") and args.preq_mode:

0 commit comments

Comments
 (0)