(func, input_source='interactive')
| 41 | os.chmod(os.path.join(path,f'concat.jpg'), stat.S_IRWXO+stat.S_IRWXG+stat.S_IRWXU) |
| 42 | |
| 43 | def generate_continually(func, input_source='interactive'): |
| 44 | if input_source == 'interactive': |
| 45 | while True: |
| 46 | raw_text, is_stop = "", False |
| 47 | if torch.distributed.get_rank() == 0: |
| 48 | raw_text = input("\nPlease Input Query (stop to exit) >>> ") |
| 49 | raw_text = raw_text.strip() |
| 50 | if not raw_text: |
| 51 | print('Query should not be empty!') |
| 52 | continue |
| 53 | if raw_text == "stop": |
| 54 | is_stop = True |
| 55 | torch.distributed.broadcast_object_list([raw_text, is_stop]) |
| 56 | else: |
| 57 | info = [raw_text, is_stop] |
| 58 | torch.distributed.broadcast_object_list(info) |
| 59 | raw_text, is_stop = info |
| 60 | if is_stop: |
| 61 | return |
| 62 | try: |
| 63 | start_time = time.time() |
| 64 | func(raw_text) |
| 65 | if torch.distributed.get_rank() == 0: |
| 66 | print("\nTaken time {:.2f}\n".format(time.time() - start_time), flush=True) |
| 67 | except (ValueError, FileNotFoundError) as e: |
| 68 | print(e) |
| 69 | continue |
| 70 | else: |
| 71 | with open(input_source, 'r', encoding="utf-8") as fin: |
| 72 | inputs = fin.readlines() |
| 73 | for line_no, raw_text in enumerate(inputs): |
| 74 | if line_no % get_data_parallel_world_size() != get_data_parallel_rank(): |
| 75 | continue |
| 76 | rk = dist.get_rank() |
| 77 | if get_model_parallel_rank() == 0: |
| 78 | print(f'Working on No. {line_no} on model group {rk}... ') |
| 79 | raw_text = raw_text.strip() |
| 80 | if len(raw_text) == 0: |
| 81 | continue |
| 82 | start_time = time.time() |
| 83 | func(raw_text) |
| 84 | if get_model_parallel_rank() == 0: |
| 85 | print("\nTaken time {:.2f}\n".format(time.time() - start_time), flush=True) |
no test coverage detected