Conversation
|
This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread. Please note that issues that do not follow the contributing guidelines are likely to be ignored. |
|
@DN6 @sayakpaul what needs to be done prior to merging this PR? |
DN6
left a comment
There was a problem hiding this comment.
Looking good 👍🏽 Some minor comments. Could we also add a test for saving/loading and setting device_map with a dummy model.
| load_connected_pipeline = kwargs.pop("load_connected_pipeline", False) | ||
| trust_remote_code = kwargs.pop("trust_remote_code", False) | ||
| dduf_file: Optional[Dict[str, DDUFEntry]] = kwargs.pop("dduf_file", None) | ||
| use_flashpack = kwargs.pop("use_flashpack", True) |
There was a problem hiding this comment.
| use_flashpack = kwargs.pop("use_flashpack", True) | |
| use_flashpack = kwargs.pop("use_flashpack", False) |
| return parsed_parameters | ||
|
|
||
|
|
||
| def load_flashpack_checkpoint(flashpack_checkpoint_path: str): |
There was a problem hiding this comment.
I don't think this is used anywhere? We can remove it if that's the case.
| subfolder=subfolder or "", | ||
| dduf_entries=dduf_entries, | ||
| ) | ||
| elif use_flashpack: |
There was a problem hiding this comment.
We can consolidate this section into something like this
if use_flashpack:
weights_name = _add_variant(FLASHPACK_WEIGHTS_NAME, variant)
elif use_safetensors:
weights_name = _add_variant(SAFETENSORS_WEIGHTS_NAME, variant)
else:
weights_name = None
if weights_name is not None:
try:
resolved_model_file = _get_model_file(
pretrained_model_name_or_path,
weights_name=weights_name,
**model_file_kwargs,
)
except IOError as e:
logger.error(f"An error occurred while trying to fetch {pretrained_model_name_or_path}: {e}")
if not allow_pickle:
raise
logger.warning(
"Defaulting to unsafe serialization. Pass `allow_pickle=False` to raise an error instead."
)| ) | ||
| flashpack_device = None | ||
| else: | ||
| flashpack_device = device_map[""] |
There was a problem hiding this comment.
| flashpack_device = device_map[""] | |
| device = device_map[""] | |
| flashpack_device = torch.device(device) if not isinstance(device, torch.device) else device |
| flashpack_device = device_map[""] | ||
| if flashpack_device in ["auto", "balanced", "balanced_low_0", "sequential"]: | ||
| raise ValueError( | ||
| "FlashPack `device_map` should be a device, not one of `auto`, `balanced`, `balanced_low_0`, `sequential`." |
There was a problem hiding this comment.
| "FlashPack `device_map` should be a device, not one of `auto`, `balanced`, `balanced_low_0`, `sequential`." | |
| "FlashPack `device_map` should not be one of `auto`, `balanced`, `balanced_low_0`, `sequential`. Use a specific device instead, e.g., `device_map='cuda'` or `device_map='cuda:0'" |
| device=flashpack_device, | ||
| **flashpack_kwargs, | ||
| ) | ||
|
|
There was a problem hiding this comment.
Also need to reset dtype_orig since this early exits.
| if dtype_orig is not None: | |
| torch.set_default_dtype(dtype_orig) |
What does this PR do?
Adds support for FlashPack
FlashPack could be used as weight format only (see:
load_flashpack_checkpoint) - keeping only weight format code would be a cleaner integration, the model loading is indeed faster[1] however part of the performance difference seems to be just due to the complexity of existingfrom_pretrainedcode, for example I noticed that_caching_allocator_warmupslows things down, alsoempty_device_cacheis called in_load_pretrained_modelwhereas FlashPack's code doesn't thus the empty cache time is excluded from FlashPack's benchmark results.is_flashpack_availablecheck logging, etc)silent,num_streams,use_distributed_loadingetc.)Benchmark
Changes from FlashPack's version:
transformersrelated code[1] For
bfloat16- withfloat16existing code appears to be fasterWho can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.