Skip to content

Commit

Permalink
code review
Browse files Browse the repository at this point in the history
  • Loading branch information
SunMarc committed Jul 22, 2024
1 parent c3bc434 commit 4723908
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/transformers/integrations/fbgemm_fp8.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# coding=utf-8
# Copyright 2024 NetEase, Inc. and the HuggingFace Inc. team. All rights reserved.
# Copyright 2024 The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
15 changes: 8 additions & 7 deletions tests/quantization/fbgemm_fp8/test_fbgemm_fp8.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from transformers.testing_utils import (
require_accelerate,
require_fbgemm_gpu,
require_read_token,
require_torch_gpu,
require_torch_multi_gpu,
slow,
Expand Down Expand Up @@ -63,6 +64,7 @@ def test_from_dict(self):
@require_torch_gpu
@require_fbgemm_gpu
@require_accelerate
@require_read_token
class FbgemmFp8Test(unittest.TestCase):
model_name = "meta-llama/Meta-Llama-3-8B"

Expand Down Expand Up @@ -148,24 +150,23 @@ def test_quantized_model_conversion(self):
nb_linears += 1

model = replace_with_fbgemm_fp8_linear(model, quantization_config=quantization_config)
nb_eetq_linear = 0
nb_fbgemm_linear = 0
for module in model.modules():
if isinstance(module, FbgemmFp8Linear):
nb_eetq_linear += 1
nb_fbgemm_linear += 1

self.assertEqual(nb_linears - 1, nb_eetq_linear)
self.assertEqual(nb_linears - 1, nb_fbgemm_linear)

# Try with `linear_weights_not_to_quantize`
with init_empty_weights():
model = OPTForCausalLM(config)
quantization_config = FbgemmFp8Config(modules_to_not_convert=["fc1"])
model = replace_with_fbgemm_fp8_linear(model, quantization_config=quantization_config)
nb_eetq_linear = 0
nb_fbgemm_linear = 0
for module in model.modules():
if isinstance(module, FbgemmFp8Linear):
nb_eetq_linear += 1
nb_fbgemm_linear += 1

self.assertEqual(nb_linears - 25, nb_eetq_linear)
self.assertEqual(nb_linears - 25, nb_fbgemm_linear)

def test_quantized_model(self):
"""
Expand Down

0 comments on commit 4723908

Please sign in to comment.