Skip to content

Allow Distributed.get_instance() without context for single-rank#1070

Merged
mcgibbon merged 2 commits into
mainfrom
fix/allow-single-rank-without-context
Apr 21, 2026
Merged

Allow Distributed.get_instance() without context for single-rank#1070
mcgibbon merged 2 commits into
mainfrom
fix/allow-single-rank-without-context

Conversation

@mcgibbon
Copy link
Copy Markdown
Contributor

@mcgibbon mcgibbon commented Apr 21, 2026

Single-rank environments like Jupyter notebooks previously could not call Distributed.get_instance() without wrapping code in Distributed.context(), even though the context manager is only needed for multi-rank distributed shutdown coordination.

Changes:

  • fme.core.distributed.Distributed.get_instance: moved the _entered check to after singleton creation and only raises when world_size > 1

  • Tests added

Fixes #1049

Previously, get_instance() raised RuntimeError when called outside
Distributed.context() regardless of the number of ranks. This made it
impossible to use in single-rank environments like Jupyter notebooks
where there is no need for the distributed context manager. Now the
error is only raised when world_size > 1, where the context manager
is actually needed to ensure proper initialization and shutdown.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@oliverwm1 oliverwm1 left a comment

Choose a reason for hiding this comment

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

Update the PR description to link the existing open issue before merging. Otherwise looks good.

@mcgibbon mcgibbon enabled auto-merge (squash) April 21, 2026 20:35
@mcgibbon mcgibbon merged commit 9df6730 into main Apr 21, 2026
7 checks passed
@mcgibbon mcgibbon deleted the fix/allow-single-rank-without-context branch April 21, 2026 20:51
jpdunc23 added a commit that referenced this pull request Apr 30, 2026
Removes `scripts/test_distributed_context.py` since this check is no
longer necessary given changes in #1070.

- [ ] Tests added
- [ ] If dependencies changed, "deps only" image rebuilt and
"latest_deps_only_image.txt" file updated
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.

Distributed.context() required even in non-distributed inference setting

2 participants