Skip to content
Open
Show file tree
Hide file tree
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
49 changes: 19 additions & 30 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ possibly-missing-attribute = "ignore"
missing-argument = "ignore"
unused-type-ignore-comment = "ignore"

[tool.bandit]
exclude_dirs = ["tests", "docs"]


[tool.coverage.run]
source = ["src/pruna"]
Expand Down Expand Up @@ -70,29 +67,21 @@ name = "pruna_internal"
url = "https://prunaai.pythonanywhere.com/simple/"
explicit = true

[[tool.uv.index]]
name = "intel-pytorch-extension"
url = "https://pytorch-extension.intel.com/release-whl/stable/cpu/cn/"
explicit = true

[tool.uv]
index-strategy = "first-index"
exclude-newer = "1 week" # protection against compromised dependencies
# trusted dev wheels that are missing an upload date
exclude-newer-package = { gptqmodel = false, "stable-fast-pruna" = false }

conflicts = [
[{ extra = "awq" }, { extra = "vbench" }],
[{ extra = "vllm" }, { extra = "vbench" }],
[{ extra = "intel" }, { extra = "awq" }],
[{ extra = "gptq" }, { extra = "awq" }],
# intel is incompatible with all stable-fast variants and vllm
[{ extra = "intel" }, { extra = "stable-fast" }, { extra = "stable-fast-extraindex" }],
[{ extra = "intel" }, { extra = "full" }, { extra = "stable-fast-extraindex" }],
[{ extra = "intel" }, { extra = "vllm" }],
[{ extra = "kvpress" }, { extra = "vbench" }],
]

[tool.uv.sources]
gptqmodel = { index = "pruna_internal", marker = "sys_platform != 'darwin' or platform_machine != 'arm64'" }
intel-extension-for-pytorch = { index = "intel-pytorch-extension" }
stable-fast-pruna = { index = "pruna_internal", extra = "stable-fast-extraindex" }

[project]
Expand Down Expand Up @@ -171,6 +160,21 @@ vllm = [
"vllm>=0.16.0",
"ray",
]
rapidata = [
"rapidata>=3.0.0",
]
upscale = [
"realesrgan",
]
evaluation = [
"pruna[rapidata]",
"pruna[lmharness]",
"outlines>1.2.0,<2.0.0",
"litellm>=1.0.0",
]
oneig-reasoning = [
"hf_transfer>=0.1.9",
]
stable-fast = [
"xformers>=0.0.30",
"stable-fast-pruna>=1.0.8,<1.0.9",
Expand All @@ -195,18 +199,12 @@ awq = [
"llmcompressor>=0.9",
"torch>=2.9.0"
]
upscale = [
"realesrgan",
]
full = [
"pruna[stable-fast]",
]
vbench = [
"vbench-pruna; sys_platform != 'darwin'",
]
rapidata = [
"rapidata>=3.0.0"
]
dev = [
"wget",
"python-dotenv",
Expand All @@ -233,22 +231,13 @@ dev = [
"types-PyYAML",
"logbar",
"pytest-xdist>=3.8.0",
"pruna[evaluation]",
]
cpu = []
lmharness = [
"lm-eval>=0.4.0"
]
evaluation = [
"pruna[rapidata]",
"pruna[lmharness]"
]

# Intel extension is tightly coupled with the torch version
intel = [
"intel-extension-for-pytorch>=2.7.0",
"torch>=2.7.0,<2.9.0",
"torchvision>=0.22.0,<0.24.0",
]
kvpress = [
"kvpress>=0.5.2",
]
Expand Down
47 changes: 30 additions & 17 deletions src/pruna/evaluation/metrics/metric_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,26 @@
)
from pruna.logging.logger import pruna_logger

_PRUNA_TASK_ROUTING_KWARGS: tuple[str, ...] = (
"vlm_type",
"model_name",
"structured_output",
"vlm_kwargs",
"api_key",
)


def _strip_task_routing_kwargs(kwargs: dict[str, Any]) -> None:
"""
Drop kwargs :class:`~pruna.evaluation.task.Task` passes when building mixed metric lists.

Torchmetrics classes often end with ``**kwargs`` and would otherwise accept bogus keys
until a lower layer raises. Stripping here keeps :class:`TorchMetricWrapper` the single
choke point between Pruna routing and torchmetrics constructors.
"""
for key in _PRUNA_TASK_ROUTING_KWARGS:
kwargs.pop(key, None)


def default_update(metric: Metric, *args, **kwargs) -> None:
"""
Expand Down Expand Up @@ -124,9 +144,7 @@ def arniqa_update(metric: ARNIQA, preds: Any) -> None:


def ssim_update(
metric: StructuralSimilarityIndexMeasure | MultiScaleStructuralSimilarityIndexMeasure,
preds: Any,
target: Any
metric: StructuralSimilarityIndexMeasure | MultiScaleStructuralSimilarityIndexMeasure, preds: Any, target: Any
) -> None:
"""
Update handler for SSIM or MS-SSIM metric.
Expand All @@ -152,29 +170,22 @@ class TorchMetrics(Enum):
"""
Enumeration of torchmetrics metrics for evaluation.

This enum provides a tuple per member (metric_factory, update_fn, call_type):
metric_factory builds the metric (typically a torchmetrics class, or
functools.partial when some constructor arguments are fixed); update_fn is
an optional custom update handler; call_type describes how inputs are paired
for the metric.
Each member value is a ``(metric_factory, update_fn, call_type)`` tuple.

Parameters
----------
value : tuple
Tuple holding metric_factory, update_fn, and call_type as described above.
``(metric_factory, update_fn, call_type)`` for this enum member.
names : str
The name of the enum member.
Enum member name.
module : str
The module where the enum is defined.
Defining module name.
qualname : str
The qualified name of the enum.
Qualified name of the enum class.
type : type
The type of the enum.
Enum metaclass type.
start : int
The start index for auto-numbering enum values.
boundary : enum.FlagBoundary or None
Boundary handling mode used by the Enum functional API for Flag and
IntFlag enums.
Auto-numbering start index for functional API enums.
"""

fid = (FrechetInceptionDistance, fid_update, "gt_y")
Expand Down Expand Up @@ -246,6 +257,7 @@ def __new__(cls, metric_name: str, call_type: str = "", **kwargs) -> StatefulMet
if metric_name == "clip_score" and call_type.startswith(PAIRWISE):
from pruna.evaluation.metrics.metric_pairwise_clip import PairwiseClipScore

_strip_task_routing_kwargs(kwargs)
return PairwiseClipScore(**kwargs)
return super().__new__(cls)

Expand All @@ -259,6 +271,7 @@ def __init__(self, metric_name: str, call_type: str = "", **kwargs) -> None:
If the metric name is not supported.
"""
self.metric_name = metric_name
_strip_task_routing_kwargs(kwargs)
super().__init__(kwargs.pop("device", None))
try:
self.metric = TorchMetrics[metric_name](**kwargs)
Expand Down
17 changes: 17 additions & 0 deletions src/pruna/evaluation/metrics/vendor/NOTICE.oneig_llm2vec
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
LLM2Vec (llm2vec package) vendored from OneIG-Benchmark.

Source: https://github.com/OneIG-Bench/OneIG-Benchmark
Commit: 41b49831e79e6dde5323618c164da1c4cf0f699d
Path: scripts/utils/llm2clip/llm2vec/

OneIG-Benchmark is licensed under the Apache License 2.0.
See the project repository for full license text.

``oneig_llm2vec/modeling_llama_encoder.py`` is derived from
McGill-NLP/LLM2Vec-Meta-Llama-3-8B-Instruct-mntp (Hugging Face Hub);
Pruna relaxes the upstream flash-attention-only constraint for CPU use.

Pruna also includes two minimal compatibility fixes in
``oneig_llm2vec/llm2vec.py``:
- Preserve constructor-provided ``doc_max_length`` instead of hardcoding 512.
- Honor ``convert_to_numpy=True`` in ``encode()`` by returning ``numpy.ndarray``.
Loading
Loading