Skip to content

Conversation

@MilesCranmer
Copy link
Contributor

@MilesCranmer MilesCranmer commented Dec 29, 2023

Running the current README example on max_memory results in this strange error:

File ~/miniforge3/envs/llms/lib/python3.9/site-packages/accelerate/utils/modeling.py:807, in get_balanced_memory(model, max_memory, no_split_module_classes, dtype, special_dtypes, low_zero)
    805 # Get default / clean up max_memory
    806 user_not_set_max_memory = max_memory is None
--> 807 max_memory = get_max_memory(max_memory)
    809 if not is_xpu_available():
    810     num_devices = len([d for d in max_memory if torch.device(d).type == "cuda" and max_memory[d] > 0])

File ~/miniforge3/envs/llms/lib/python3.9/site-packages/accelerate/utils/modeling.py:693, in get_max_memory(max_memory)
    690     return max_memory
    692 for key in max_memory:
--> 693     if isinstance(max_memory[key], str):
    694         max_memory[key] = convert_file_size_to_int(max_memory[key])
    696 # Need to sort the device by type to make sure that we allocate the gpu first.
    697 # As gpu/xpu are represented by int, we need to sort them first.

TypeError: string indices must be integers

This is because the new max_memory syntax in accelerate expects a dictionary: https://huggingface.co/docs/accelerate/v0.25.0/en/concept_guides/big_model_inference#designing-a-device-map.

This PR also:

  • Updates the README example to account for multiple devices
  • Fixes the model name not being enclosed in matching quotes

- The new `max_memory` syntax expects a dictionary
- This change also accounts for multiple devices
@TimDettmers
Copy link
Collaborator

Thank you, Miles! Accelerate updated the behavior of max_memory. @younesbelkada can you confirm that it is not required to pass all devices together with max_memory or what is simplest usage?

@TimDettmers TimDettmers added Medium Priority (will be worked on after all high priority issues) Low Risk Risk of bugs in transformers and other libraries labels Jan 2, 2024
@Titus-von-Koeller Titus-von-Koeller added the Documentation Improvements or additions to documentation label Jan 23, 2024
Copy link
Collaborator

@younesbelkada younesbelkada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM thanks !

@Titus-von-Koeller Titus-von-Koeller merged commit 94c7f2c into bitsandbytes-foundation:main Jan 25, 2024
@Titus-von-Koeller
Copy link
Collaborator

Thanks a lot @MilesCranmer for raising this 🤗 Looking forward to further contributions, if you feel like it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Low Risk Risk of bugs in transformers and other libraries Medium Priority (will be worked on after all high priority issues)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants