Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Autodetect number of devices for torchrun executor #11482

Merged
merged 6 commits into from
Jan 10, 2025
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions nemo/collections/llm/recipes/run/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,31 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import Optional

import nemo_run as run
import torch


@run.cli.factory
def torchrun(devices: int = 8) -> run.Config[run.LocalExecutor]:
"""Local executor using torchrun."""
def torchrun(devices: Optional[int] = None) -> run.Config[run.LocalExecutor]:
"""
Local executor using torchrun.

Args:
devices (Optional[int]): Number of devices to use. If None, it will use all available CUDA devices.

Returns:
run.Config[run.LocalExecutor]: Configuration for the local executor using torchrun.
"""
env_vars = {
"TORCH_NCCL_AVOID_RECORD_STREAMS": "1",
}

if devices is None:
janekl marked this conversation as resolved.
Show resolved Hide resolved
assert torch.cuda.is_available()
devices = torch.cuda.device_count()

executor = run.Config(
run.LocalExecutor,
ntasks_per_node=devices,
Expand Down
Loading