"...text-generation-inference.git" did not exist on "f9958ee191057cadf0c6c1f41577eae86819812c"
Unverified Commit 019139f7 authored by Philip Meier's avatar Philip Meier Committed by GitHub
Browse files

make _setup_fill_arg serializable (#6730)

parent af54e564
import functools
import numbers import numbers
from collections import defaultdict from collections import defaultdict
from typing import Any, Callable, Dict, Sequence, Tuple, Type, Union from typing import Any, Callable, Dict, Sequence, Tuple, Type, Union
import PIL.Image import PIL.Image
...@@ -43,13 +43,19 @@ def _check_fill_arg(fill: Union[FillType, Dict[Type, FillType]]) -> None: ...@@ -43,13 +43,19 @@ def _check_fill_arg(fill: Union[FillType, Dict[Type, FillType]]) -> None:
raise TypeError("Got inappropriate fill arg") raise TypeError("Got inappropriate fill arg")
def _default_fill(fill: FillType) -> FillType:
return fill
def _setup_fill_arg(fill: Union[FillType, Dict[Type, FillType]]) -> Dict[Type, FillType]: def _setup_fill_arg(fill: Union[FillType, Dict[Type, FillType]]) -> Dict[Type, FillType]:
_check_fill_arg(fill) _check_fill_arg(fill)
if isinstance(fill, dict): if isinstance(fill, dict):
return fill return fill
return defaultdict(lambda: fill) # type: ignore[return-value, arg-type] # This weird looking construct only exists, since `lambda`'s cannot be serialized by pickle.
# If it were possible, we could replace this with `defaultdict(lambda: fill)`
return defaultdict(functools.partial(_default_fill, fill))
def _check_padding_arg(padding: Union[int, Sequence[int]]) -> None: def _check_padding_arg(padding: Union[int, Sequence[int]]) -> None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment