(message, ranks=None, path=None)
| 154 | |
| 155 | |
| 156 | def print_json_dist(message, ranks=None, path=None): |
| 157 | from deepspeed import comm as dist |
| 158 | """Print message when one of following condition meets |
| 159 | |
| 160 | + not dist.is_initialized() |
| 161 | + dist.get_rank() in ranks if ranks is not None or ranks = [-1] |
| 162 | |
| 163 | Args: |
| 164 | message (str) |
| 165 | ranks (list) |
| 166 | path (str) |
| 167 | |
| 168 | """ |
| 169 | should_log = not dist.is_initialized() |
| 170 | ranks = ranks or [] |
| 171 | my_rank = dist.get_rank() if dist.is_initialized() else -1 |
| 172 | if ranks and not should_log: |
| 173 | should_log = ranks[0] == -1 |
| 174 | should_log = should_log or (my_rank in set(ranks)) |
| 175 | if should_log: |
| 176 | message['rank'] = my_rank |
| 177 | import json |
| 178 | with open(path, 'w') as outfile: |
| 179 | json.dump(message, outfile) |
| 180 | os.fsync(outfile) |
| 181 | |
| 182 | |
| 183 | def get_log_level_from_string(log_level_str): |
no test coverage detected
searching dependent graphs…