Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,15 @@ def quant_interface(model: Any, dtype: Union[Dtype] = Dtype.int8, device: Device
model.to(device_orig)
elif device == Device.cuda and dtype in [Dtype.fp8, torch.float8_e5m2]:
try:
from float8_experimental.float8_dynamic_linear import ( # type: ignore
Float8DynamicLinear,
)
from float8_experimental.float8_linear_utils import ( # type: ignore
swap_linear_with_float8_linear,
)
from torchao.quantization import quantize_, float8_dynamic_activation_float8_weight
except ImportError:
raise ImportError(
"float8_experimental is not installed."
"https://github.com/pytorch-labs/float8_experimental "
"with commit `88e9e507c56e59c5f17edf513ecbf621b46fc67d`"
"FP8 quantization requires torchao. "
"Install with: pip install torchao\n"
)
logger.info("using dtype=fp8")
swap_linear_with_float8_linear(model, Float8DynamicLinear)
# Use quantize_ with the float8 configuration
quantize_(model, float8_dynamic_activation_float8_weight())
else:
raise ValueError(f"Quantization is not supported on {device} with dtype {dtype}.")
return model
Expand Down
21 changes: 20 additions & 1 deletion libs/infinity_emb/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions libs/infinity_emb/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ black = "^24.10.0"
types-chardet = "^5.0.4.6"
mypy-protobuf = "^3.0.0"


[tool.poetry.group.dev.dependencies]
torchao = "^0.11.0"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider moving torchao to main dependencies section with optional=true if it's needed for core FP8 functionality


[tool.poetry.extras]
ct2=["ctranslate2","sentence-transformers","torch","transformers"]
optimum=["optimum"]
Expand Down