Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Prev Previous commit
Next Next commit
Fix dist env uninit
  • Loading branch information
SwordFaith committed Jun 25, 2025
commit e16c29e6fcfda23d336d32bc35022adcce859019
13 changes: 13 additions & 0 deletions 13 tests/workers/rollout/test_sglang_multi_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import tempfile
from unittest.mock import MagicMock, patch

import torch
import torch.distributed as dist
from omegaconf import DictConfig, OmegaConf

from verl.interactions.base import BaseInteraction
Expand Down Expand Up @@ -84,9 +86,16 @@ def create_mock_config_with_multi_interactions():
return config, interaction_config_path


def setup_distributed():
"""Initialize distributed environment if not already initialized."""
if not dist.is_initialized():
dist.init_process_group(backend="nccl" if torch.cuda.is_available() else "gloo")


class TestSGLangMultiInteraction:
def test_initialize_multiple_interactions(self):
"""Test that SGLangRollout can initialize multiple interactions."""
setup_distributed()
config, temp_config_path = create_mock_config_with_multi_interactions()

try:
Expand Down Expand Up @@ -120,6 +129,7 @@ def test_initialize_multiple_interactions(self):

def test_interaction_selection_by_name(self):
"""Test that interactions are selected by name from interaction_kwargs."""
setup_distributed()
config, temp_config_path = create_mock_config_with_multi_interactions()

try:
Expand Down Expand Up @@ -176,6 +186,7 @@ def test_interaction_selection_by_name(self):

def test_fallback_to_default_interaction(self):
"""Test fallback to default interaction when name is not specified."""
setup_distributed()
# Create config with gsm8k interaction
interaction_config = {"interaction": [{"name": "gsm8k", "class_name": "tests.workers.rollout.test_sglang_multi_interaction.MockInteraction", "config": {}}]}

Expand Down Expand Up @@ -223,6 +234,7 @@ def test_fallback_to_default_interaction(self):

def test_error_on_missing_interaction(self):
"""Test that error is raised when requested interaction is not found."""
setup_distributed()
config, temp_config_path = create_mock_config_with_multi_interactions()

try:
Expand Down Expand Up @@ -251,6 +263,7 @@ def test_error_on_missing_interaction(self):

def test_backward_compatibility_no_interaction_config(self):
"""Test backward compatibility when no interaction config is provided."""
setup_distributed()
# Create config without interaction config
config = DictConfig(
{
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.