Writes a signal file to the specified directory. This function creates a signal file in the specified directory. If the directory does Note: Only local rank zero writes the signal file. All other ranks are expected to wait for the signal file. Args: signal_file_name (str): The
(signal_file_name: str, dir_path: Optional[str] = None)
| 645 | |
| 646 | |
| 647 | def write_signal_file(signal_file_name: str, dir_path: Optional[str] = None) -> str: |
| 648 | """Writes a signal file to the specified directory. |
| 649 | |
| 650 | This function creates a signal file in the specified directory. If the directory does |
| 651 | Note: Only local rank zero writes the signal file. All other ranks are expected to wait for the signal file. |
| 652 | |
| 653 | Args: |
| 654 | signal_file_name (str): The name of the signal file. |
| 655 | dir_path (str, optional): The full path to the directory in which to create the signal file. If ``None``, |
| 656 | the current working directory will be used. |
| 657 | """ |
| 658 | if dir_path is not None: |
| 659 | os.makedirs(dir_path, exist_ok=True) |
| 660 | |
| 661 | signal_file_path = os.path.join(dir_path or os.getcwd(), signal_file_name) |
| 662 | if get_local_rank() == 0: |
| 663 | with open(signal_file_path, 'w') as _f: |
| 664 | _f.write('local rank zero done') |
| 665 | |
| 666 | return signal_file_path |
| 667 | |
| 668 | |
| 669 | @contextmanager |
no test coverage detected