Skip to content

Raise ValueError instead of a bare string in ParallelismConfig.get_device_mesh - #4064

Merged
SunMarc merged 1 commit into
huggingface:mainfrom
lollinng:accelerate-get-device-mesh-raise-valueerror
Jun 9, 2026
Merged

Raise ValueError instead of a bare string in ParallelismConfig.get_device_mesh#4064
SunMarc merged 1 commit into
huggingface:mainfrom
lollinng:accelerate-get-device-mesh-raise-valueerror

Conversation

@lollinng

@lollinng lollinng commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Problem

ParallelismConfig.get_device_mesh raises a bare string when device_type is missing:

raise ("You need to pass a device_type e.g cuda to build the device mesh")

In Python 3 you can only raise exception instances, so this throws
TypeError: exceptions must derive from BaseException instead of surfacing the
intended message — confusing for anyone who forgets to pass device_type.

Fix

Raise ValueError with the same message.

Testing done (CPU)

BEFORE  raise <str>        -> TypeError: exceptions must derive from BaseException
AFTER   raise ValueError   -> ValueError: You need to pass a device_type ...
REAL get_device_mesh(None) -> ValueError (good)

ruff clean.

…mesh

get_device_mesh raised a string literal when device_type was not provided:
`raise ("You need to pass a device_type ...")`. In Python 3 raising a
non-exception throws `TypeError: exceptions must derive from BaseException`,
hiding the intended guidance. Raise ValueError with the message instead.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

@SunMarc SunMarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks !

@SunMarc
SunMarc merged commit bd20807 into huggingface:main Jun 9, 2026
19 of 25 checks passed
@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants