Skip to content

Commit

Permalink
feat: use cloudpickle to serialize transformers_modules by value
Browse files Browse the repository at this point in the history
Signed-off-by: Travis Johnson <tsjohnso@us.ibm.com>
  • Loading branch information
tjohnson31415 committed Oct 7, 2024
1 parent 151ef4e commit d03107a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
23 changes: 23 additions & 0 deletions vllm/transformers_utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,29 @@ def get_config(
)
config.update({key: value})

if trust_remote_code:
# With trust_remote_code, the config is typically an instance of a
# custom class imported from the HF modules cache.
#
# The class will not be importable in Ray workers by default (and won't
# exist at all on other nodes), which breaks serialization of the
# config. Here we tell the serialization library used by Ray to pass
# instances of these generated classes by value instead of by reference
# (eg. the class definition is serialized along with its data).
#
# See: https://github.com/cloudpipe/cloudpickle?tab=readme-ov-file#overriding-pickles-serialization-mechanism-for-importable-constructs
try:
import cloudpickle
import ray
import transformers_modules
cloudpickle.register_pickle_by_value(transformers_modules)
# Ray vendors its own version of cloudpickle
ray.cloudpickle.register_pickle_by_value(transformers_modules)
# ignore import errors in the case that trust_remote_code is set
# unnecessarily and transformers_modules does not exist
except ImportError:
pass

return config


Expand Down
2 changes: 2 additions & 0 deletions vllm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,8 @@ def flatten_2d_lists(lists: List[List[T]]) -> List[T]:
return [item for sublist in lists for item in sublist]


# TODO: This function can be removed if transformer_modules classes are
# serialized by value when communicating between processes
def init_cached_hf_modules() -> None:
"""
Lazy initialization of the Hugging Face modules.
Expand Down

0 comments on commit d03107a

Please sign in to comment.