Skip to content

Commit

Permalink
remove util related code
Browse files Browse the repository at this point in the history
  • Loading branch information
yukirora committed Jul 16, 2021
1 parent 419dea2 commit 1f898fc
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion tests/benchmarks/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"""Utilities for benchmark tests."""

import os
import socket
from contextlib import closing
import multiprocessing as multiprocessing
from multiprocessing import Process

from superbench.benchmarks import BenchmarkRegistry
from superbench.common.utils import network


def clean_simulated_ddp_distributed_env():
Expand All @@ -20,6 +21,18 @@ def clean_simulated_ddp_distributed_env():
os.environ.pop('MASTER_PORT')


def get_free_port():
"""Get a free port in current system.
Return:
port (int): a free port in current system.
"""
with closing(socket.socket(socket.AF_INET, socket.SOCK_STREAM)) as s:
s.bind(('', 0))
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
return s.getsockname()[1]


def setup_simulated_ddp_distributed_env(world_size, local_rank, port):
"""Function to setup the simulated DDP distributed envionment variables."""
os.environ['WORLD_SIZE'] = str(world_size)
Expand Down

0 comments on commit 1f898fc

Please sign in to comment.