Skip to content

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

Open
lollinng wants to merge 1 commit into
huggingface:mainfrom
lollinng:accelerate-get-device-mesh-raise-valueerror
Open

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

Conversation

@lollinng
Copy link
Copy Markdown

@lollinng lollinng commented Jun 4, 2026

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>
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.

1 participant