This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.distributed as dist | |
| from torch.distributed.elastic.multiprocessing.errors import record | |
| import datetime | |
| import os | |
| @record | |
| def main(): | |
| os.environ["NCCL_ASYNC_ERROR_HANDLING"] = "1" | |
| dist.init_process_group(backend="nccl", timeout=datetime.timedelta(seconds=1800)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch | |
| import torch.distributed as dist | |
| from torch.distributed.elastic.multiprocessing.errors import record | |
| import datetime | |
| import os | |
| @record | |
| def main(): | |
| os.environ["NCCL_ASYNC_ERROR_HANDLING"] = "1" | |
| dist.init_process_group(backend="nccl", timeout=datetime.timedelta(seconds=1800)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import onnxruntime as ort | |
| import torch | |
| from time import perf_counter | |
| ort_session = ort.InferenceSession("resnet50.onnx", providers=["CPUExecutionProvider"]) | |
| print(ort.get_device()) | |
| inputs = {} | |
| for inp in ort_session.get_inputs(): | |
| inputs[inp.name] = torch.rand(inp.shape).numpy() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pickle | |
| def save_pkl(filename_, inp): | |
| with open(filename_, 'wb') as f: | |
| pickle.dump(inp, f) | |
| def load_pkl(filename_, ): | |
| with open(filename_, 'rb') as f: | |
| l_file = pickle.load(f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import torch, time, gc, contextlib | |
| # Timing utilities | |
| start_time = None | |
| @contextlib.contextmanager | |
| def add_timer(local_msg): | |
| try: | |
| start_timer() | |
| yield |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pynvml import * | |
| nvmlInit() | |
| deviceCount = nvmlDeviceGetCount() | |
| # assume its 1 for now | |
| handle = nvmlDeviceGetHandleByIndex(0) | |
| util = nvmlDeviceGetUtilizationRates(handle) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from contextlib import contextmanager | |
| # Context Manager using object | |
| class ContextManager(): | |
| def __init__(self, name): | |
| self.name = name | |
| def __enter__(self, ): | |
| print('nvtx_marker on for: {}'.format(self.name)) | |
| return self |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import multiprocessing as mp | |
| import time as time | |
| def square(): | |
| for i in range(1000000): | |
| x = pow(i, 2) | |
| if __name__ == "__main__": | |
| num_iter = 10 | |
| start = time.time() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import threading | |
| import time as time | |
| def square(): | |
| for i in range(1000000): | |
| x = pow(i, 2) | |
| if __name__ == "__main__": | |
| num_iter = 10 | |
| start = time.time() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import threading | |
| import time as time | |
| def display(i): | |
| print("Thread id: ", i) | |
| time.sleep(4) | |
| if __name__ == "__main__": |
NewerOlder