Skip to content

Commit ab3acc7

Browse files
authored
check pil dep (#3114)
1 parent 8965409 commit ab3acc7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lm_eval/evaluator.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@ def evaluate(
752752
samples = (
753753
hash_dict_images(samples)
754754
if os.environ.get("LMEVAL_HASHMM", "1") != "0"
755+
and (hasattr(lm, "MULTIMODAL"))
755756
else samples
756757
)
757758
results_dict["samples"] = dict(samples)

lm_eval/utils.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,11 @@ def hash_dict_images(data_dict):
576576
dict: A new dictionary with the same structure as `data_dict`, but with all
577577
bytes and PIL.Image.Image objects replaced by their hashes.
578578
"""
579-
from PIL import Image
580579

581580
def _process_value(value):
582581
# Bytes -> hash
582+
from PIL import Image
583+
583584
if isinstance(value, (bytes, bytearray)):
584585
return convert_bytes_to_hash(value)
585586
# PIL Image -> hash
@@ -600,4 +601,8 @@ def _process_value(value):
600601
if not isinstance(data_dict, dict):
601602
raise TypeError("Input must be a dictionary")
602603

603-
return {key: _process_value(val) for key, val in data_dict.items()}
604+
return (
605+
{key: _process_value(val) for key, val in data_dict.items()}
606+
if importlib.util.find_spec("PIL")
607+
else data_dict
608+
)

0 commit comments

Comments
 (0)