ci: Add script to check for pickle usage in community (#22863)

Add script to check for pickle usage in community.
This commit is contained in:
Eugene Yurtsev
2024-06-13 16:13:15 -04:00
committed by GitHub
parent 77209f315e
commit 8f7cc73817
9 changed files with 65 additions and 8 deletions

View File

@@ -242,7 +242,7 @@ def _load_pickled_fn_from_hex_string(
raise ValueError(f"Please install cloudpickle>=2.0.0. Error: {e}")
try:
return cloudpickle.loads(bytes.fromhex(data))
return cloudpickle.loads(bytes.fromhex(data)) # ignore[pickle]: explicit-opt-in
except Exception as e:
raise ValueError(
f"Failed to load the pickled function from a hexadecimal string. Error: {e}"

View File

@@ -36,7 +36,9 @@ def _send_pipeline_to_device(pipeline: Any, device: int) -> Any:
"""Send a pipeline to a device on the cluster."""
if isinstance(pipeline, str):
with open(pipeline, "rb") as f:
pipeline = pickle.load(f)
# This code path can only be triggered if the user
# passed allow_dangerous_deserialization=True
pipeline = pickle.load(f) # ignore[pickle]: explicit-opt-in
if importlib.util.find_spec("torch") is not None:
import torch