ezpz.distΒΆ
- See ezpz/
dist.py
dist.py
Contains methods for initializing distributed communication.
all_reduce(obj, op=None, implementation=None)
ΒΆ
All-reduce obj across all ranks using MPI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Picklable payload to reduce. |
required |
op
|
Optional[Op | reduce_op]
|
Reduction operation; defaults to |
None
|
implementation
|
Optional[str]
|
Override to |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
The reduced value. |
Examples:
Source code in src/ezpz/dist.py
barrier(device=None, group=torch.distributed.GroupMember.WORLD, async_op=False, device_ids=None)
ΒΆ
Barrier for all processes in the group.
This collective blocks processes until the whole group enters this function, if async_op is False, or if async work handle is called on wait().
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device | int | str
|
The device to synchronize. If None, the default device will be used. Defaults to None. |
None
|
group
|
ProcessGroup | None
|
The process group to work on. If None, the default process group (WORLD) will be used. Defaults to torch.distributed.GroupMember.WORLD. |
WORLD
|
async_op
|
bool
|
If True, the barrier will be asynchronous. |
False
|
device_ids
|
str | Iterable | None
|
The device IDs to synchronize. |
None
|
Returns:
| Type | Description |
|---|---|
Work | None
|
torch.distributed.Work | None: If async_op is True, returns a work handle. If async_op is False, returns None. |
Examples:
Source code in src/ezpz/dist.py
broadcast(obj, root=0)
ΒΆ
Broadcast obj from root to all ranks using MPI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
obj
|
Any
|
Picklable payload to share. |
required |
root
|
int
|
Rank that originates the value. |
0
|
Returns:
| Type | Description |
|---|---|
Any
|
The broadcast payload. |
Examples:
Source code in src/ezpz/dist.py
check(framework='pytorch', backend='deepspeed', port='5432')
ΒΆ
Check if the framework is installed and working
Source code in src/ezpz/dist.py
cleanup()
ΒΆ
Cleanup the distributed environment. This function destroys the process group if it is initialized.
Examples:
Source code in src/ezpz/dist.py
get_cpus_per_node()
ΒΆ
Get the number of CPUs per node.
Returns:
| Type | Description |
|---|---|
int
|
Number of logical CPUs on the local node. |
Examples:
Source code in src/ezpz/dist.py
get_device(type=None, as_torch_device=None)
ΒΆ
Alias for get_torch_device.
Examples:
Source code in src/ezpz/dist.py
get_device_properties(device=None)
ΒΆ
Get the properties of the specified device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
str | Device | int
|
The device to get properties for. If None, the current device will be used. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict | None
|
A dictionary containing the device properties. |
Source code in src/ezpz/dist.py
2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 | |
get_dist_info(framework=None, verbose=None, hostfile=None)
ΒΆ
Get distributed info.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
framework
|
str
|
Framework to use. Defaults to None. |
None
|
verbose
|
bool
|
Whether to print the info. Defaults to None. |
None
|
hostfile
|
PathLike
|
Path to the hostfile. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, str | int | list]
|
Dictionary containing the distributed info. |
Source code in src/ezpz/dist.py
get_free_port()
ΒΆ
Get a free port on the local machine.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
A free port number that can be used for communication. |
Source code in src/ezpz/dist.py
get_gpus_per_node()
ΒΆ
Get the number of GPUs per node.
Returns:
| Type | Description |
|---|---|
int
|
Number of visible GPU devices on the local node. |
Examples:
Source code in src/ezpz/dist.py
get_hostfile_with_fallback(hostfile=None)
ΒΆ
Get the hostfile from the environment or create one if it doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostfile
|
Optional[PathLike]
|
Optional explicit hostfile path. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to a usable hostfile. |
Examples:
Source code in src/ezpz/dist.py
2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 | |
get_hostname()
ΒΆ
Get the hostname of the current machine.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The hostname of the current machine. |
Source code in src/ezpz/dist.py
get_hosts_from_hostfile(hostfile=None)
ΒΆ
Get hosts from the hostfile or environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostfile
|
str | Path
|
Path to the hostfile. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[str, list[str]]
|
tuple[str, list[str]]: Tuple containing the hostfile path and a list of hosts. |
Examples:
Source code in src/ezpz/dist.py
get_local_rank()
ΒΆ
Return get_rank() % get_gpus_per_node()
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The local rank of the current process within its node. This is calculated as the current rank modulo the number of GPUs per node. |
Examples:
Source code in src/ezpz/dist.py
get_machine(hostname=None)
ΒΆ
Get the machine name from the hostname.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
The hostname to check. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The machine name. |
Examples:
Source code in src/ezpz/dist.py
get_node_index()
ΒΆ
get_nodes_from_hostfile(hostfile)
ΒΆ
Get the nodes from the hostfile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostfile
|
PathLike
|
The path to the hostfile. |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
list[str]: A list of nodes from the hostfile. |
Source code in src/ezpz/dist.py
get_num_nodes(hostfile=None)
ΒΆ
Get the number of nodes from the hostfile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostfile
|
Optional[PathLike]
|
Optional hostfile path to count nodes from. |
None
|
Examples:
Source code in src/ezpz/dist.py
get_rank()
ΒΆ
Get current MPI rank.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The rank of the current process in the MPI world. |
Examples:
Source code in src/ezpz/dist.py
get_torch_backend()
ΒΆ
Get the current PyTorch backend.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The current PyTorch backend. |
Source code in src/ezpz/dist.py
get_torch_backend_on_xpu()
ΒΆ
Deal with breaking change introduced in torch 2.6:
See: https://github.com/pytorch/pytorch/pull/141856
Examples:
1 2 | |
Source code in src/ezpz/dist.py
get_torch_device(*, device_type=None, as_torch_device=None)
ΒΆ
Get the current PyTorch device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_type
|
str
|
The type of device to return. If None, it will be determined automatically. Defaults to None. |
None
|
as_torch_device
|
bool
|
If True, return a torch.device object. If False, return a string representing the device type. Defaults to False. |
None
|
Returns:
| Type | Description |
|---|---|
str | device
|
str | torch.device: The current PyTorch device. If as_torch_device is True, returns a torch.device object. If as_torch_device is False, returns a string representing the device type. |
Examples:
Source code in src/ezpz/dist.py
get_torch_device_type(device_type=None)
ΒΆ
Get the current PyTorch device type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device_type
|
str
|
The type of device to return. If None, it will be determined automatically. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The current PyTorch device type. Possible values are "cpu", "mps", "xpu", or "cuda". |
Examples:
Source code in src/ezpz/dist.py
get_torch_version_as_float()
ΒΆ
Get the PyTorch version as a float.
Returns:
| Name | Type | Description |
|---|---|---|
float |
float
|
The PyTorch version as a float, e.g., 1.10.0 -> 1.10 |
get_world_size(total=None, in_use=None)
ΒΆ
Get the total number of *PUs available or currently in use. Args: total (bool, optional): If True, return the total number of *PUs available. Defaults to None. in_use (bool, optional): If True, return the number of *PUs currently in use. Defaults to None.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The total number of *PUs available or currently in use.
If both |
Examples:
Source code in src/ezpz/dist.py
get_world_size_in_use()
ΒΆ
Get number of currently in use MPI ranks
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of currently in use MPI ranks. This is the size of the MPI communicator. It is the number of processes that are currently running and participating in the distributed computation. |
Examples:
Source code in src/ezpz/dist.py
get_world_size_total()
ΒΆ
Calculate total AVAILABLE *PUs as:
total = [num_hosts] * [num_*pu_per_host]
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The total number of available *PUs across all nodes. This is the product of the number of nodes and the number of *PUs per node. |
Examples:
Source code in src/ezpz/dist.py
include_file(f)
ΒΆ
Check if a file should be included based on its extension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
PathLike
|
The file path to check. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the file should be included, False otherwise. |
Source code in src/ezpz/dist.py
init_deepspeed(dist_backend=None, auto_mpi_discovery=True, distributed_port=29500, verbose=True, timeout=None, init_method=None, dist_init_required=None, config=None, rank=None, world_size=None)
ΒΆ
Initialize DeepSpeed distributed environment.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dist_backend
|
str
|
The distributed backend to use. Defaults to None. |
None
|
auto_mpi_discovery
|
bool
|
Whether to automatically discover MPI. Defaults to True. |
True
|
distributed_port
|
int | str
|
The port for distributed communication. Defaults to 29500. |
29500
|
verbose
|
bool
|
Whether to print verbose logs. Defaults to True. |
True
|
timeout
|
int | None
|
Timeout in seconds for distributed initialization. Defaults to None. |
None
|
init_method
|
str
|
Initialization method for distributed training. Defaults to None. |
None
|
dist_init_required
|
bool
|
Whether distributed initialization is required. Defaults to None. |
None
|
config
|
dict
|
DeepSpeed configuration dictionary. Defaults to None. |
None
|
rank
|
int | None
|
Rank of the current process. Defaults to None. |
None
|
world_size
|
int | None
|
Total number of processes. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ImportError
|
If DeepSpeed is not installed. |
Exception
|
If there is an error during DeepSpeed initialization. |
Examples:
Source code in src/ezpz/dist.py
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 | |
init_process_group(rank, world_size, timeout, backend=None, device_id=None)
ΒΆ
Initialize the PyTorch distributed process group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rank
|
int | str
|
The rank of the current process. |
required |
world_size
|
int | str
|
The total number of processes. |
required |
timeout
|
str | int | timedelta
|
Timeout for the process group initialization. |
required |
backend
|
str
|
The backend to use for distributed training. Defaults to None, which will use the default backend based on the device. |
None
|
Source code in src/ezpz/dist.py
log_dict_as_bulleted_list(d, name=None)
ΒΆ
Print a dict as bullets.
Source code in src/ezpz/dist.py
make_hostfile_from_slurm_env(outfile=None)
ΒΆ
Make a hostfile from the SLURM_NODELIST environment variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
outfile
|
Optional[PathLike]
|
Optional destination path for the generated hostfile. |
None
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to the created hostfile. |
Examples:
Source code in src/ezpz/dist.py
print_dist_setup(framework=None, hostfile=None, display=True)
ΒΆ
Print distributed setup.
Source code in src/ezpz/dist.py
query_environment()
ΒΆ
Query environment variables for info about distributed setup
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
dict[str, int]: A dictionary containing the distributed setup information.
Includes keys like 'world_size', 'rank', and 'local_rank'.
If the environment variables are not set, it falls back to using
|
Examples:
Source code in src/ezpz/dist.py
run_bash_command(cmd)
ΒΆ
Run a bash command and return the output. Args: cmd (str): The command to run.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
The output of the command. |
Source code in src/ezpz/dist.py
run_ddp(fn, world_size)
ΒΆ
Run a function in a distributed data parallel (DDP) setup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable
|
The function to run in DDP. |
required |
world_size
|
int
|
The total number of processes to run. |
required |
Examples:
Source code in src/ezpz/dist.py
seed_everything(seed)
ΒΆ
Set random seed for reproducibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
seed
|
int
|
Random seed to set. |
required |
Source code in src/ezpz/dist.py
setup(framework='pytorch', backend='DDP', port='5432', seed=None, precision=None, ngpus=None)
ΒΆ
Setup distributed environment for the specified framework.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
framework
|
str
|
The framework to use for distributed training. Defaults to "pytorch". |
'pytorch'
|
backend
|
str
|
The backend to use for distributed training. Defaults to "DDP". |
'DDP'
|
port
|
str
|
The port to use for distributed communication. Defaults to "5432". |
'5432'
|
seed
|
int
|
Random seed for reproducibility. Defaults to None. |
None
|
precision
|
str
|
Precision to use for training. Defaults to None. |
None
|
ngpus
|
int
|
Number of GPUs to use. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The rank returned by the selected setup routine. |
Source code in src/ezpz/dist.py
setup_tensorflow(precision=None, ngpus=None)
ΒΆ
Initialize TensorFlow + Horovod for Distributed Training
Source code in src/ezpz/dist.py
1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 | |
setup_torch(framework=None, backend=None, port=None, seed=None, timeout=None, verbose=False, tensor_parallel_size=1, pipeline_parallel_size=1, context_parallel_size=1, tensor_parallel_backend=None, pipeline_parallel_backend=None, context_parallel_backend=None, data_parallel_backend=None, device_id=None)
ΒΆ
Setup torch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
str
|
Backend to use. Defaults to None. |
None
|
port
|
str | int
|
Port to use. Defaults to None. |
None
|
seed
|
int
|
Seed to use. Defaults to None. |
None
|
timeout
|
str | int
|
Timeout to use. Defaults to None. |
None
|
verbose
|
bool
|
Whether to print the info. Defaults to False. |
False
|
tensor_parallel_size
|
int
|
Tensor parallel size. Defaults to 1. |
1
|
pipeline_parallel_size
|
int
|
Pipeline parallel size. Defaults to 1. |
1
|
context_parallel_size
|
int
|
Context parallel size. Defaults to 1. |
1
|
tensor_parallel_backend
|
str
|
Tensor parallel backend. Defaults to None. |
None
|
pipeline_parallel_backend
|
str
|
Pipeline parallel backend. Defaults to None. |
None
|
context_parallel_backend
|
str
|
Context parallel backend. Defaults to None. |
None
|
data_parallel_backend
|
str
|
Data parallel backend. Defaults to None. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Rank of the process. |
Examples:
Source code in src/ezpz/dist.py
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 | |
setup_torch_DDP(port='2345', timeout=3600, backend=None, device_id=None)
ΒΆ
Setup PyTorch Distributed Data Parallel (DDP) environment. Args: port (str, optional): The port to use for distributed communication. Defaults to "2345". timeout (int | str | timedelta, optional): Timeout for the process group initialization. Defaults to 3600 seconds. backend (str, optional): The backend to use for distributed training. Defaults to None, which will use the default backend based on the device.
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
dict[str, int]: A dictionary containing the distributed setup information. Includes keys like 'world_size', 'rank', and 'local_rank'. |
Source code in src/ezpz/dist.py
1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 | |
setup_torch_distributed(framework=None, backend=None, tensor_parallel_size=1, pipeline_parallel_size=1, context_parallel_size=1, tensor_parallel_backend=None, pipeline_parallel_backend=None, context_parallel_backend=None, data_parallel_backend=None, device_id=None, port=None, timeout=None)
ΒΆ
Setup distributed environment for PyTorch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
framework
|
str
|
The framework to use for distributed training. Defaults to None, which will use "ddp". |
None
|
backend
|
str
|
The backend to use for distributed training. Defaults to None, which will use the default backend based on the device. |
None
|
tensor_parallel_size
|
int
|
Size of tensor parallelism. Defaults to 1. |
1
|
pipeline_parallel_size
|
int
|
Size of pipeline parallelism. Defaults to 1. |
1
|
context_parallel_size
|
int
|
Size of context parallelism. Defaults to 1. |
1
|
tensor_parallel_backend
|
str
|
Backend for tensor parallelism. Defaults to None. |
None
|
pipeline_parallel_backend
|
str
|
Backend for pipeline parallelism. Defaults to None. |
None
|
context_parallel_backend
|
str
|
Backend for context parallelism. Defaults to None. |
None
|
data_parallel_backend
|
str
|
Backend for data parallelism. Defaults to None. |
None
|
port
|
str | int
|
Port for distributed communication. Defaults to "1234". |
None
|
timeout
|
str | int
|
Timeout for distributed initialization. Defaults to 3600 seconds. |
None
|
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
dict[str, int]: A dictionary containing the distributed setup information. Includes keys like 'world_size', 'rank', and 'local_rank'. |
Raises:
| Type | Description |
|---|---|
AssertionError
|
If the framework is not one of the supported frameworks. Supported frameworks are "ddp", "ds", "deepspeed", "horovod", and "hvd". |
ValueError
|
If the backend is not one of the supported backends. Supported backends are "ddp", "ds", "deepspeed", "horovod", and "hvd". |
Examples:
Source code in src/ezpz/dist.py
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 | |
setup_wandb(project_name=None, entity=None, config=None, start_method='thread', outdir=None, init_timeout=300, allow_val_change=False)
ΒΆ
Setup wandb for logging.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
project_name
|
str
|
The name of the project. Defaults to None. |
None
|
entity
|
str
|
The entity name. Defaults to None. |
None
|
config
|
dict | DictConfig
|
The configuration dictionary. Defaults to None. |
None
|
start_method
|
str
|
The start method for wandb. Defaults to "thread". |
'thread'
|
outdir
|
str | Path | PathLike
|
The output directory. Defaults to None. |
None
|
init_timeout
|
int
|
The timeout for wandb initialization. Defaults to 300. |
300
|
allow_val_change
|
bool
|
Whether to allow value changes in wandb config. Defaults to False. |
False
|
Examples:
Source code in src/ezpz/dist.py
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 | |
synchronize(device=None)
ΒΆ
Synchronize the given device.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
device
|
device | int | str
|
The device to synchronize. If None, the default device will be used. Defaults to None. |
None
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Examples:
Source code in src/ezpz/dist.py
timeit(func)
ΒΆ
Decorator to time a function and log the duration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func
|
Callable
|
Callable to wrap. |
required |
Examples:
Source code in src/ezpz/dist.py
timeitlogit(rank=None, record=True, verbose=False, prefix=None)
ΒΆ
Decorator to time a function and optionally log to wandb and stdout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rank
|
Optional[int]
|
Rank whose logger should emit messages. Defaults to |
None
|
record
|
bool
|
Whether to log timing to wandb if available. |
True
|
verbose
|
bool
|
Whether to log timing to stdout on the selected rank. |
False
|
prefix
|
str | None
|
Optional prefix for wandb metrics (defaults to |
None
|
Examples:
Source code in src/ezpz/dist.py
wrap_model(model, use_fsdp=True, dtype='bfloat16')
ΒΆ
Wrap a model with DDP or FSDP depending on use_fsdp and world size.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Model to wrap. |
required |
use_fsdp
|
Optional[bool]
|
If True, prefer FSDP; otherwise use DDP. |
True
|
dtype
|
str
|
Parameter dtype when using FSDP. |
'bfloat16'
|
Examples:
Source code in src/ezpz/dist.py
wrap_model_for_ddp(model)
ΒΆ
Wrap the model for distributed data parallel (DDP) training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
The model to wrap. |
required |
Examples:
Source code in src/ezpz/dist.py
wrap_with_ddp(model)
ΒΆ
Alias for wrap_model_for_ddp for backward compatibility.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Model to wrap with DDP. |
required |
Examples:
Source code in src/ezpz/dist.py
wrap_with_fsdp(model, dtype='bfloat16')
ΒΆ
Wrap a model with FSDP using the given parameter dtype.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Module
|
Model to wrap with FSDP. |
required |
dtype
|
str
|
Parameter dtype for mixed precision (e.g., |
'bfloat16'
|
Examples:
Source code in src/ezpz/dist.py
write_hostfile_from_list_of_hosts(hosts, hostfile=None, rank_zero_only=True)
ΒΆ
Write a list of hosts to the hostfile.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hosts
|
list[str]
|
A list of hostnames to write to the hostfile. |
required |
hostfile
|
PathLike
|
The path to the hostfile. Defaults to None. |
None
|
rank_zero_only
|
bool
|
If True, only rank 0 will write the hostfile. Defaults to True. |
True
|
Source code in src/ezpz/dist.py
write_localhost_to_hostfile(hostfile)
ΒΆ
Write 'localhost' to the hostfile