diff --git a/tb_plugin/torch_tb_profiler/io/azureblob.py b/tb_plugin/torch_tb_profiler/io/azureblob.py index 2f99e80d2..30f8aa009 100644 --- a/tb_plugin/torch_tb_profiler/io/azureblob.py +++ b/tb_plugin/torch_tb_profiler/io/azureblob.py @@ -23,6 +23,7 @@ def __init__(self): raise ImportError('azure-storage-blob must be installed for Azure Blob support.') self.connection_string = os.environ.get('AZURE_STORAGE_CONNECTION_STRING', None) + # pyrefly: ignore [bad-param-name-override] def exists(self, dirname): """Returns whether the path is a directory or not.""" basename, parts = self.split_blob_path(dirname) @@ -34,6 +35,7 @@ def exists(self, dirname): else: return basename == parts[0] + # pyrefly: ignore [bad-param-name-override] def read(self, filename, binary_mode=False, size=None, continue_from=None): """Reads contents of a file to a string.""" logger.info('azure blob: starting reading file %s' % filename) @@ -125,6 +127,7 @@ def listdir(self, dirname): items.append(item) return items + # pyrefly: ignore [bad-param-name-override] def makedirs(self, dirname): """No need create directory since the upload blob will automatically create""" pass @@ -145,6 +148,7 @@ def walk(self, top, topdown=True, onerror=None): for blob in blobs: dirname, basename = self.split(blob.name) dirname = 'https://{}/{}/{}'.format(account, container, dirname) + # pyrefly: ignore [missing-attribute] results.setdefault(dirname, []).append(basename) for key, value in results.items(): yield key, None, value diff --git a/tb_plugin/torch_tb_profiler/io/cache.py b/tb_plugin/torch_tb_profiler/io/cache.py index d93cdfd0c..4ca3067bf 100644 --- a/tb_plugin/torch_tb_profiler/io/cache.py +++ b/tb_plugin/torch_tb_profiler/io/cache.py @@ -15,7 +15,9 @@ class Cache: def __init__(self, cache_dir=None): + # pyrefly: ignore [missing-attribute] self._lock = mp.Lock() + # pyrefly: ignore [missing-attribute] self._manager = mp.Manager() self._cache_dict = self._manager.dict() self._cache_dir = cache_dir diff --git a/tb_plugin/torch_tb_profiler/io/file.py b/tb_plugin/torch_tb_profiler/io/file.py index a67aea21d..94b662b9e 100644 --- a/tb_plugin/torch_tb_profiler/io/file.py +++ b/tb_plugin/torch_tb_profiler/io/file.py @@ -25,9 +25,7 @@ logger = utils.get_logger() try: - # pyre-fixme[21]: Could not find module `boto3`. import boto3 - # pyre-fixme[21]: Could not find module `botocore.exceptions`. import botocore.exceptions S3_ENABLED = True @@ -101,6 +99,7 @@ def __init__(self): def exists(self, filename): return os.path.exists(filename) + # pyrefly: ignore [bad-param-name-override] def read(self, filename, binary_mode=False, size=None, continue_from=None): mode = "rb" if binary_mode else "r" encoding = None if binary_mode else "utf8" @@ -113,6 +112,7 @@ def read(self, filename, binary_mode=False, size=None, continue_from=None): with open(filename, mode, encoding=encoding) as f: if offset is not None: f.seek(offset) + # pyrefly: ignore [bad-argument-type] data = f.read(size) # The new offset may not be `offset + len(data)`, due to decoding # and newline translation. @@ -210,6 +210,7 @@ def exists(self, filename): return True return False + # pyrefly: ignore [bad-param-name-override] def read(self, filename, binary_mode=False, size=None, continue_from=None): """Reads contents of a file to a string.""" s3 = boto3.resource("s3", endpoint_url=self._s3_endpoint) @@ -333,6 +334,7 @@ def listdir(self, dirname): keys.append(key) return keys + # pyrefly: ignore [bad-param-name-override] def makedirs(self, dirname): """Creates a directory and all parent/intermediate directories.""" if not self.exists(dirname): @@ -400,8 +402,10 @@ def __iter__(self): def _read_buffer_to_offset(self, new_buff_offset): old_buff_offset = self.buff_offset + # pyrefly: ignore [bad-argument-type] read_size = min(len(self.buff), new_buff_offset) - old_buff_offset self.buff_offset += read_size + # pyrefly: ignore [unsupported-operation] return self.buff[old_buff_offset: old_buff_offset + read_size] def read(self, n=None): diff --git a/tb_plugin/torch_tb_profiler/io/gs.py b/tb_plugin/torch_tb_profiler/io/gs.py index 783ac7d4b..1999b0316 100644 --- a/tb_plugin/torch_tb_profiler/io/gs.py +++ b/tb_plugin/torch_tb_profiler/io/gs.py @@ -21,6 +21,7 @@ def __init__(self): if not storage: raise ImportError('google-cloud-storage must be installed for Google Cloud Blob support.') + # pyrefly: ignore [bad-param-name-override] def exists(self, dirname): """Returns whether the path is a directory or not.""" bucket_name, path = self.bucket_and_path(dirname) @@ -28,6 +29,7 @@ def exists(self, dirname): bucket = client.bucket(bucket_name) return bucket.blob(path).exists() + # pyrefly: ignore [bad-param-name-override] def read(self, filename, binary_mode=False, size=None, continue_from=None): raise NotImplementedError @@ -67,6 +69,7 @@ def listdir(self, dirname): items.append(item) return items + # pyrefly: ignore [bad-param-name-override] def makedirs(self, dirname): """No need create directory since the upload blob will automatically create""" pass @@ -87,6 +90,7 @@ def walk(self, top, topdown=True, onerror=None): for blob in blobs: dirname, basename = self.split(blob.name) dirname = 'gs://{}/{}'.format(bucket_name, dirname) + # pyrefly: ignore [missing-attribute] results.setdefault(dirname, []).append(basename) for key, value in results.items(): yield key, None, value diff --git a/tb_plugin/torch_tb_profiler/io/hdfs.py b/tb_plugin/torch_tb_profiler/io/hdfs.py index 5ec231cca..1de9ef6ed 100644 --- a/tb_plugin/torch_tb_profiler/io/hdfs.py +++ b/tb_plugin/torch_tb_profiler/io/hdfs.py @@ -16,13 +16,13 @@ class HadoopFileSystem(RemotePath, BaseFileSystem): def __init__(self) -> None: super().__init__() - # pyre-fixme[11]: Annotation `HadoopFileSystem` is not defined as a type. def get_fs(self) -> arrow.HadoopFileSystem: return fsspec.filesystem("hdfs") def exists(self, filename): return self.get_fs().exists(filename) + # pyrefly: ignore [bad-param-name-override] def read(self, filename, binary_mode=False, size=None, continue_from=None): fs = self.get_fs() mode = "rb" if binary_mode else "r" @@ -69,4 +69,4 @@ def support_append(self): return False def download_file(self, file_to_download, file_to_save): - return self.get_fs().download(file_to_download, file_to_save, recursive=True) \ No newline at end of file + return self.get_fs().download(file_to_download, file_to_save, recursive=True) diff --git a/tb_plugin/torch_tb_profiler/plugin.py b/tb_plugin/torch_tb_profiler/plugin.py index c9b41e76f..f05ab6083 100644 --- a/tb_plugin/torch_tb_profiler/plugin.py +++ b/tb_plugin/torch_tb_profiler/plugin.py @@ -38,7 +38,6 @@ def wrapper(*args, **kwargs): exceptions.HTTPException.get_headers = decorate_headers(exceptions.HTTPException.get_headers) -# pyre-fixme[11]: Annotation `TBPlugin` is not defined as a type. class TorchProfilerPlugin(base_plugin.TBPlugin): """TensorBoard plugin for Torch Profiler.""" @@ -52,7 +51,6 @@ def __init__(self, context: base_plugin.TBContext): Args: context: A base_plugin.TBContext instance. """ - # pyre-fixme[19]: Expected 0 positional arguments. super(TorchProfilerPlugin, self).__init__(context) if not context.logdir and context.flags.logdir_spec: dirs = context.flags.logdir_spec.split(',') @@ -133,6 +131,7 @@ def get_plugin_apps(self): def frontend_metadata(self): return base_plugin.FrontendMetadata(es_module_path='/index.js', disable_reload=True) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def runs_route(self, request: werkzeug.Request): with self._runs_lock: @@ -144,6 +143,7 @@ def runs_route(self, request: werkzeug.Request): } return self.respond_as_json(data) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def views_route(self, request: werkzeug.Request): name = request.args.get('run') @@ -152,6 +152,7 @@ def views_route(self, request: werkzeug.Request): views_list = [view.display_name for view in run.views] return self.respond_as_json(views_list) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def workers_route(self, request: werkzeug.Request): name = request.args.get('run') @@ -160,6 +161,7 @@ def workers_route(self, request: werkzeug.Request): run = self._get_run(name) return self.respond_as_json(run.get_workers(view)) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def spans_route(self, request: werkzeug.Request): name = request.args.get('run') @@ -168,6 +170,7 @@ def spans_route(self, request: werkzeug.Request): run = self._get_run(name) return self.respond_as_json(run.get_spans(worker)) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def overview_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -176,15 +179,18 @@ def overview_route(self, request: werkzeug.Request): data = profile.overview is_gpu_used = profile.has_runtime or profile.has_kernel or profile.has_memcpy_or_memset normal_workers = [worker for worker in run.workers if worker != 'All'] + # pyrefly: ignore [unsupported-operation] data['environments'] = [{'title': 'Number of Worker(s)', 'value': str(len(normal_workers))}, {'title': 'Device Type', 'value': 'GPU' if is_gpu_used else 'CPU'}] if profile.gpu_summary and profile.gpu_tooltip: + # pyrefly: ignore [unsupported-operation] data['gpu_metrics'] = {'title': 'GPU Summary', 'data': profile.gpu_summary, 'tooltip': profile.gpu_tooltip} return self.respond_as_json(data) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def operation_pie_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -195,6 +201,7 @@ def operation_pie_route(self, request: werkzeug.Request): else: return self.respond_as_json(profile.operation_pie_by_name) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def operation_table_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -205,6 +212,7 @@ def operation_table_route(self, request: werkzeug.Request): else: return self.respond_as_json(profile.operation_table_by_name) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def operation_stack_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -218,12 +226,14 @@ def operation_stack_route(self, request: werkzeug.Request): else: return self.respond_as_json(profile.operation_stack_by_name[str(op_name)]) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def kernel_pie_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) return self.respond_as_json(profile.kernel_pie) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def kernel_table_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -234,12 +244,14 @@ def kernel_table_route(self, request: werkzeug.Request): else: return self.respond_as_json(profile.kernel_op_table) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def kernel_tc_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) return self.respond_as_json(profile.tc_pie) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def trace_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -270,26 +282,31 @@ def trace_route(self, request: werkzeug.Request): headers.extend(TorchProfilerPlugin.headers) return werkzeug.Response(raw_data, content_type=TorchProfilerPlugin.CONTENT_TYPE, headers=headers) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def dist_gpu_info_route(self, request: werkzeug.Request): profile = self._get_distributed_profile_for_request(request) return self.respond_as_json(profile.gpu_info) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def comm_overlap_route(self, request: werkzeug.Request): profile = self._get_distributed_profile_for_request(request) return self.respond_as_json(profile.steps_to_overlap) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def comm_wait_route(self, request: werkzeug.Request): profile = self._get_distributed_profile_for_request(request) return self.respond_as_json(profile.steps_to_wait) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def comm_ops_route(self, request: werkzeug.Request): profile = self._get_distributed_profile_for_request(request) return self.respond_as_json(profile.comm_ops) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def memory_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -304,6 +321,7 @@ def memory_route(self, request: werkzeug.Request): return self.respond_as_json( profile.get_memory_stats(start_ts=start_ts, end_ts=end_ts, memory_metric=memory_metric), True) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def memory_curve_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -312,6 +330,7 @@ def memory_curve_route(self, request: werkzeug.Request): return self.respond_as_json( profile.get_memory_curve(time_metric=time_metric, memory_metric=memory_metric), True) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def memory_events_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -328,6 +347,7 @@ def memory_events_route(self, request: werkzeug.Request): profile.get_memory_events(start_ts, end_ts, time_metric=time_metric, memory_metric=memory_metric), True) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def module_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) @@ -340,12 +360,14 @@ def module_route(self, request: werkzeug.Request): span = request.args.get('span') raise exceptions.NotFound('could not find the run for %s/%s/%s' % (name, worker, span)) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def op_tree_route(self, request: werkzeug.Request): profile = self._get_profile_for_request(request) content = profile.get_operator_tree() return self.respond_as_json(content, True) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def diff_run_route(self, request: werkzeug.Request): base, exp = self.get_diff_runs(request) @@ -353,6 +375,7 @@ def diff_run_route(self, request: werkzeug.Request): content = diff_stats.get_diff_tree_summary() return self.respond_as_json(content, True) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def diff_run_node_route(self, request: werkzeug.Request): base, exp = self.get_diff_runs(request) @@ -364,6 +387,7 @@ def diff_run_node_route(self, request: werkzeug.Request): content = diff_stat.get_diff_node_summary(path) return self.respond_as_json(content, True) + # pyrefly: ignore [bad-argument-type] @wrappers.Request.application def static_file_route(self, request: werkzeug.Request): filename = os.path.basename(request.path) @@ -511,6 +535,7 @@ def _load_run(self, run_dir): logger.info('Run %s loaded', name) self._queue.put(run) except Exception as ex: + # pyrefly: ignore [unbound-name] logger.warning('Failed to load run %s. Exception=%s', ex, name, exc_info=True) t = threading.current_thread() diff --git a/tb_plugin/torch_tb_profiler/profiler/communication.py b/tb_plugin/torch_tb_profiler/profiler/communication.py index 7d8a9f862..b8bbf6789 100644 --- a/tb_plugin/torch_tb_profiler/profiler/communication.py +++ b/tb_plugin/torch_tb_profiler/profiler/communication.py @@ -87,6 +87,7 @@ def analyze_communication_nodes(comm_node_list: List[CommunicationNode])\ total_size = 1 for size in comm_node.input_shape[i]: total_size *= size + # pyrefly: ignore [unsupported-operation] total_comm_stats[comm_node.name][1] += total_size * bytes_one_value total_comm_stats[comm_node.name][2].extend(comm_node.kernel_ranges) total_comm_stats[comm_node.name][3].extend(comm_node.real_time_ranges) @@ -100,7 +101,9 @@ def analyze_communication_nodes(comm_node_list: List[CommunicationNode])\ ] for _, stats in total_comm_stats.items(): + # pyrefly: ignore [unsupported-operation] stats[2] = get_ranges_sum(merge_ranges(stats[2])) + # pyrefly: ignore [unsupported-operation] stats[3] = get_ranges_sum(merge_ranges(stats[3])) # pyre-fixme[7]: Expected `Tuple[Dict[str, Tuple[int, int]], Dict[str, diff --git a/tb_plugin/torch_tb_profiler/profiler/data.py b/tb_plugin/torch_tb_profiler/profiler/data.py index c6aeceae3..0c27654dd 100644 --- a/tb_plugin/torch_tb_profiler/profiler/data.py +++ b/tb_plugin/torch_tb_profiler/profiler/data.py @@ -113,7 +113,6 @@ def parse(worker, span, path, cache_dir): @staticmethod def from_json(worker, span, trace_json: Dict): profile = RunProfileData(worker, span, trace_json) - # pyre-fixme[16]: `None` has no attribute `__enter__`. with utils.timing('Data processing'): profile.process() profile.analyze() @@ -175,6 +174,7 @@ def _preprocess_file(trace_path, cache_dir): def process(self): with utils.timing('EventParser.parse'): parser = EventParser() + # pyrefly: ignore [bad-assignment] self.tid2tree, self.pl_tid2tree = parser.parse(self.events, self.forward_backward_events) self.has_runtime = parser.has_runtime @@ -194,6 +194,7 @@ def process(self): logger.debug('ModuleAggregator') with utils.timing('ModuleAggregator aggegation'): module_aggregator = ModuleAggregator() + # pyrefly: ignore [bad-argument-type] module_aggregator.aggregate(self.tid2tree) self.op_list_groupby_name = module_aggregator.op_list_groupby_name self.op_list_groupby_name_input = module_aggregator.op_list_groupby_name_input @@ -215,6 +216,7 @@ def process(self): logger.debug('TensorCoresParser') tensorcores_parser = TensorCoresParser.parse_events( + # pyrefly: ignore [bad-argument-type] self.tid2tree, module_aggregator.ops, self.gpu_metrics_parser.gpu_ids) self.tc_eligible_ops_kernel_ratio = tensorcores_parser.tc_eligible_ops_kernel_ratio self.tc_ratio = tensorcores_parser.tc_ratio @@ -230,11 +232,13 @@ def process(self): memory_events = self._memory_events() if memory_events: memory_parser = MemoryParser(memory_events) + # pyrefly: ignore [bad-argument-type] self.memory_snapshot = memory_parser.find_memory_nodes(self.tid2tree) def analyze(self): self.recommendations = [] + # pyrefly: ignore [missing-attribute] dataloader_ratio = self.avg_costs.costs[ProfileRole.DataLoader] / self.avg_costs.costs[ProfileRole.Total] if dataloader_ratio > 0.05: percentage = dataloader_ratio * 100 @@ -255,9 +259,11 @@ def analyze(self): # If it's a pure CPU run, then self.tc_used_ratio is None, this rule will not be triggered. if (major is not None and major >= 7 and self.tc_used_ratio == 0.0 and + # pyrefly: ignore [unsupported-operation] self.tc_eligible_ops_kernel_ratio > 0.0): url = 'https://pytorch.org/docs/stable/amp.html' self.recommendations.append( + # pyrefly: ignore [unsupported-operation] f'Kernels with {round(self.tc_eligible_ops_kernel_ratio * 100)}%' ' time are launched by Tensor Cores eligible operators. ' f"You could enable {href('Automatic Mixed Precision', url)} to speedup by using FP16.") @@ -287,6 +293,7 @@ def _analyze_distributed_metrics(self): f"It is recommended to {href('use DistributedDataParallel instead of DataParallel', url)}" ' to do multi-GPU training.') + # pyrefly: ignore [not-iterable] if self.use_ddp and CommLibTypes.Nccl not in self.comm_lib and self.device_props: for device_prop in self.device_props: major = device_prop.get('computeMajor') @@ -301,6 +308,7 @@ def _analyze_distributed_metrics(self): self.recommendations.append(text) break + # pyrefly: ignore [missing-attribute] communication_ratio = self.avg_costs.costs[ProfileRole.Communication] / self.avg_costs.costs[ProfileRole.Total] if communication_ratio > 0.1: percentage = communication_ratio * 100 @@ -361,4 +369,5 @@ def __init__(self, run_profile_data: RunProfileData): self.step_comm_stats = None def communication_parse(self): + # pyrefly: ignore [bad-argument-type] self.step_comm_stats, self.total_comm_stats = analyze_communication_nodes(self.comm_node_list) diff --git a/tb_plugin/torch_tb_profiler/profiler/diffrun/operator.py b/tb_plugin/torch_tb_profiler/profiler/diffrun/operator.py index b5acd31c0..67954beee 100644 --- a/tb_plugin/torch_tb_profiler/profiler/diffrun/operator.py +++ b/tb_plugin/torch_tb_profiler/profiler/diffrun/operator.py @@ -103,7 +103,6 @@ def total_duration(self): def __str__(self) -> str: if isinstance(self.op_nodes, list): - # pyre-fixme[16]: Item `OperatorNode` of `Union[List[OperatorNode], # OperatorNode]` has no attribute `__getitem__`. return f'{self.name}: {len(self.op_nodes)}: {self.op_nodes[0].name}: {self.total_duration}' else: @@ -118,7 +117,6 @@ def get_operators_and_kernels(self) -> Tuple[List[OperatorNode], List[DeviceNode ops: List[OperatorNode] = [] kernels: List[DeviceNode] = [] for n in nodes: - # pyre-fixme[16]: Item `List` of `Union[List[OperatorNode], # OperatorNode]` has no attribute `get_operator_and_kernels`. o, k = n.get_operator_and_kernels() ops.extend(o) diff --git a/tb_plugin/torch_tb_profiler/profiler/diffrun/tree.py b/tb_plugin/torch_tb_profiler/profiler/diffrun/tree.py index 1efc69b26..0f9c05a87 100644 --- a/tb_plugin/torch_tb_profiler/profiler/diffrun/tree.py +++ b/tb_plugin/torch_tb_profiler/profiler/diffrun/tree.py @@ -162,11 +162,9 @@ def print_node(node: Union[DiffNode, DiffStats], level: int, index: int, file=sy def print_ops(op: Operators, prefix: str = INDENT, file=sys.stdout): if isinstance(op.op_nodes, list): - # pyre-fixme[16]: Item `OperatorNode` of `Union[List[OperatorNode], # OperatorNode]` has no attribute `__iter__`. for n in op.op_nodes: file.write(f'{prefix}{n.name}\n') else: - # pyre-fixme[16]: Item `List` of `Union[List[OperatorNode], OperatorNode]` # has no attribute `name`. file.write(f'{prefix}{op.op_nodes.name}\n') diff --git a/tb_plugin/torch_tb_profiler/profiler/event_parser.py b/tb_plugin/torch_tb_profiler/profiler/event_parser.py index c3bc3ebcf..307087ef1 100644 --- a/tb_plugin/torch_tb_profiler/profiler/event_parser.py +++ b/tb_plugin/torch_tb_profiler/profiler/event_parser.py @@ -18,7 +18,6 @@ logger = utils.get_logger() -# pyre-fixme[19]: Expected 1 positional argument. CommLibTypes = IntEnum('CommLibTypes', ['Nccl', 'Gloo'], start=0) @@ -120,6 +119,7 @@ def parse_nodes(self, events: Iterable[BaseEvent]): def _update_communication_node(self, event: KernelEvent): """Update the communication node by using the TraceEvent instance""" external_id = event.external_id + # pyrefly: ignore [no-matching-overload] comm_node = self.communication_data.get(external_id) if comm_node: ts = event.ts @@ -209,10 +209,8 @@ def _parse_node(self, # `DurationEvent`. comm_node = CommunicationNode.create(event) if event.name in NcclOpNameSet: - # pyre-fixme[16]: `IntEnum` has no attribute `Nccl`. self.comm_lib.add(CommLibTypes.Nccl) if event.name in GlooOpNameSet: - # pyre-fixme[16]: `IntEnum` has no attribute `Gloo`. self.comm_lib.add(CommLibTypes.Gloo) ts = event.ts dur = event.duration @@ -405,7 +403,6 @@ def _update_steps_duration(self, is_use_gpu = prev_step_end_time is not None if is_use_gpu: for i_step in range(len(self.steps)): - # pyre-fixme[6]: For 1st argument expected `SupportsRichComparisonT` # but got `Optional[int]`. step_start_time = max(prev_step_end_time, self.steps[i_step][0]) step_end_time = self.steps[i_step][1] @@ -446,10 +443,10 @@ def _update_steps_duration(self, class EventParser(NodeParserMixin, StepParser): def __init__(self): super().__init__() + # pyrefly: ignore [bad-assignment, bad-specialization] self.comm_node_list: Dict[CommunicationNode] = None def parse(self, events: Iterable[BaseEvent], fwd_bwd_map: Dict[int, int]) -> Dict[int, List[OperatorNode]]: - # pyre-fixme[16]: `None` has no attribute `__enter__`. with utils.timing('EventParser: parse nodes'): tid2list, tid2zero_rt_list, staled_device_nodes, pl_tid2list = self.parse_nodes(events) diff --git a/tb_plugin/torch_tb_profiler/profiler/gpu_metrics_parser.py b/tb_plugin/torch_tb_profiler/profiler/gpu_metrics_parser.py index 4be6094a6..d4d470520 100644 --- a/tb_plugin/torch_tb_profiler/profiler/gpu_metrics_parser.py +++ b/tb_plugin/torch_tb_profiler/profiler/gpu_metrics_parser.py @@ -83,18 +83,23 @@ def get_bucket_info(range_micro_seconds): current_bucket = buckets_ranges[0] while (current_range_index < len(self.kernel_ranges_per_device[gpu_id]) and current_bucket_index < buckets): + # pyrefly: ignore [unsupported-operation] if current_bucket[1] <= current_range[0]: current_bucket_index += 1 current_bucket = buckets_ranges[current_bucket_index] if current_bucket_index < buckets \ else None + # pyrefly: ignore [unsupported-operation] elif current_bucket[0] >= current_range[1]: current_range_index += 1 if current_range_index < len(self.kernel_ranges_per_device[gpu_id]): current_range = self.kernel_ranges_per_device[gpu_id][current_range_index] else: + # pyrefly: ignore [unsupported-operation] left_bound = max(current_range[0], current_bucket[0]) + # pyrefly: ignore [unsupported-operation] right_bound = min(current_range[1], current_bucket[1]) gpu_utilization_timeline[gpu_id][current_bucket_index] += (right_bound - left_bound) + # pyrefly: ignore [unsupported-operation] if current_bucket[1] < current_range[1]: current_bucket_index += 1 current_bucket = buckets_ranges[current_bucket_index] if current_bucket_index < buckets \ @@ -111,6 +116,7 @@ def get_bucket_info(range_micro_seconds): start_time = buckets_ranges[-1][1] self.gpu_util_buckets[gpu_id].append((start_time, 0)) + # pyrefly: ignore [bad-assignment] self.kernel_ranges_per_device = None # Release memory. def calculate_approximated_sm_efficiency(self, steps_start_time, steps_end_time): @@ -138,6 +144,7 @@ def calculate_avg(approximated_sm_efficiency_ranges, total_dur): if len(approximated_sm_efficiency_ranges) > 0: self.approximated_sm_efficiency_ranges[gpu_id] = approximated_sm_efficiency_ranges + # pyrefly: ignore [bad-assignment] self.blocks_per_sm_per_device = None # Release memory. # Weighted average. Weighted by kernel's time duration. @@ -154,6 +161,7 @@ def calculate_occupancy(self, steps_start_time, steps_end_time): total_occupancy += r[2] * dur total_time += dur if total_time > 0: + # pyrefly: ignore [unsupported-operation] self.avg_occupancy_per_device[gpu_id] = total_occupancy / total_time @classmethod @@ -285,13 +293,16 @@ def process_gpu(gpu_id: int): # the legacy chrome tracing file would not have gpu info. pass gpu_metrics_data.append({'title': 'GPU Utilization', 'value': '{} %'.format( + # pyrefly: ignore [unsupported-operation] round(self.gpu_utilization[gpu_id] * 100, 2))}) if self.avg_approximated_sm_efficiency_per_device[gpu_id] is not None: gpu_metrics_data.append({'title': 'Est. SM Efficiency', 'value': '{} %'.format( + # pyrefly: ignore [unsupported-operation] round(self.avg_approximated_sm_efficiency_per_device[gpu_id] * 100, 2))}) has_sm_efficiency = True if self.avg_occupancy_per_device[gpu_id] is not None: gpu_metrics_data.append({'title': 'Est. Achieved Occupancy', 'value': '{} %'.format( + # pyrefly: ignore [no-matching-overload] round(self.avg_occupancy_per_device[gpu_id], 2))}) has_occupancy = True if tc_ratio[gpu_id] is not None: diff --git a/tb_plugin/torch_tb_profiler/profiler/loader.py b/tb_plugin/torch_tb_profiler/profiler/loader.py index c95c86edb..ef1b5da2f 100644 --- a/tb_plugin/torch_tb_profiler/profiler/loader.py +++ b/tb_plugin/torch_tb_profiler/profiler/loader.py @@ -28,7 +28,6 @@ def __init__(self, name, run_dir, caches: io.Cache): self.run_name = name self.run_dir = run_dir self.caches = caches - # pyre-fixme[16]: Module `multiprocessing` has no attribute `Queue`. self.queue = Queue() def load(self): @@ -74,6 +73,7 @@ def load(self): if r is not None: run.add_profile(r) if d is not None: + # pyrefly: ignore [bad-argument-type] distributed_run.add_profile(d) distributed_profiles = self._process_spans(distributed_run) diff --git a/tb_plugin/torch_tb_profiler/profiler/memory_parser.py b/tb_plugin/torch_tb_profiler/profiler/memory_parser.py index 91d2f578f..01b402f31 100644 --- a/tb_plugin/torch_tb_profiler/profiler/memory_parser.py +++ b/tb_plugin/torch_tb_profiler/profiler/memory_parser.py @@ -158,7 +158,6 @@ def traverse_node_memory(node: OperatorNode): for op_name, op_agg in agg_result[0].items(): op_calls[op_name] += op_agg.calls - # pyre-fixme[9]: result has type `Dict[str, Dict[str, List[int]]]`; used as # `DefaultDict[Variable[_KT], DefaultDict[Variable[_KT], Variable[_VT]]]`. result: Dict[str, Dict[str, List[int]]] = defaultdict(defaultdict) for device, node_metrics in memory_metrics_keyed_by_nodename.items(): diff --git a/tb_plugin/torch_tb_profiler/profiler/module_op.py b/tb_plugin/torch_tb_profiler/profiler/module_op.py index d790115cf..d15b6698b 100644 --- a/tb_plugin/torch_tb_profiler/profiler/module_op.py +++ b/tb_plugin/torch_tb_profiler/profiler/module_op.py @@ -158,6 +158,7 @@ def _build_module_hierarchy(events: List[PythonFunctionEvent]) -> List[Module]: # will produce a unique and unambiguous hierarchy. def append_hierarchy(e_id) -> Module: e = id_to_event[e_id] + # pyrefly: ignore [missing-attribute] module = Module(e.name, e.module_id) for id in module_child_map[e_id]: child = append_hierarchy(id) diff --git a/tb_plugin/torch_tb_profiler/profiler/node.py b/tb_plugin/torch_tb_profiler/profiler/node.py index 1af74856a..1a3289910 100644 --- a/tb_plugin/torch_tb_profiler/profiler/node.py +++ b/tb_plugin/torch_tb_profiler/profiler/node.py @@ -31,9 +31,12 @@ def __init__(self, name: str, start_time: int, end_time: int, type: str, tid: in def get_node_argument(event: DurationEvent): kwargs = {} kwargs['name'] = event.name + # pyrefly: ignore [unsupported-operation] kwargs['start_time'] = event.ts + # pyrefly: ignore [unsupported-operation] kwargs['end_time'] = event.ts + event.duration kwargs['type'] = event.type + # pyrefly: ignore [unsupported-operation] kwargs['tid'] = event.tid external_id = getattr(event, 'external_id', None) @@ -65,6 +68,7 @@ def __init__(self, input_shape: List[List[int]], input_type: List[str], **kwargs @classmethod def create(cls, event: OperatorEvent): kwargs = BaseNode.get_node_argument(event) + # pyrefly: ignore [bad-argument-type] return cls(input_shape=event.input_shape, input_type=event.input_type, **kwargs) diff --git a/tb_plugin/torch_tb_profiler/profiler/op_agg.py b/tb_plugin/torch_tb_profiler/profiler/op_agg.py index 88222c32a..36dbc6c20 100644 --- a/tb_plugin/torch_tb_profiler/profiler/op_agg.py +++ b/tb_plugin/torch_tb_profiler/profiler/op_agg.py @@ -119,11 +119,17 @@ def aggregate_kernels(kernel_list: List[DeviceNode]) -> List[KernelAggByNameOp]: class ModuleAggregator: def __init__(self): + # pyrefly: ignore [bad-assignment] self.op_list_groupby_name: List[OperatorAgg] = None # For Operator-view. + # pyrefly: ignore [bad-assignment] self.op_list_groupby_name_input: List[OperatorAgg] = None # For Operator-view. + # pyrefly: ignore [bad-assignment] self.kernel_list_groupby_name_op: List[KernelAggByNameOp] = None # For Kernel-view. + # pyrefly: ignore [bad-assignment] self.stack_lists_group_by_name: Dict[str, List[OperatorAgg]] = None + # pyrefly: ignore [bad-assignment] self.stack_lists_group_by_name_input: Dict[str, List[OperatorAgg]] = None + # pyrefly: ignore [bad-assignment] self.ops: List[OperatorNode] = None def aggregate(self, tid2tree: Dict[int, OperatorNode]): diff --git a/tb_plugin/torch_tb_profiler/profiler/op_tree.py b/tb_plugin/torch_tb_profiler/profiler/op_tree.py index 288a57e01..f2ea5dc9c 100644 --- a/tb_plugin/torch_tb_profiler/profiler/op_tree.py +++ b/tb_plugin/torch_tb_profiler/profiler/op_tree.py @@ -20,7 +20,9 @@ class OpTreeBuilder: BACKWARD_ACCUMULATE_GRAD = 'autograd::engine::evaluate_function: torch::autograd::AccumulateGrad' def __init__(self): + # pyrefly: ignore [bad-assignment] self.main_tid: int = None + # pyrefly: ignore [bad-assignment] self.tid2tree: Dict[int, OperatorNode] = None def build_tree(self, @@ -87,6 +89,7 @@ def _set_main_tid(self): if tid != backward_tid or backward_tid is None } # get the maximum length as the main thread + # pyrefly: ignore [no-matching-overload] self.main_tid = max(tid2len, key=tid2len.get) def _find_backward_tid(self): diff --git a/tb_plugin/torch_tb_profiler/profiler/overall_parser.py b/tb_plugin/torch_tb_profiler/profiler/overall_parser.py index ad92b90e3..578aa4813 100644 --- a/tb_plugin/torch_tb_profiler/profiler/overall_parser.py +++ b/tb_plugin/torch_tb_profiler/profiler/overall_parser.py @@ -107,6 +107,7 @@ def aggregate(self, steps: List[Tuple[int, int]], role_ranges: List[List[Tuple[i intersection_ranges_lists([step], role_ranges[ProfileRole.CpuOp])) comm_costs.communication = get_ranges_sum( intersection_ranges_lists([step], role_ranges[ProfileRole.Communication])) + # pyrefly: ignore [bad-assignment] comm_costs.other = self.steps_costs[i].costs[ProfileRole.Total] +\ comm_costs.overlap - comm_costs.computation - comm_costs.communication self.communication_overlap.append(comm_costs) diff --git a/tb_plugin/torch_tb_profiler/profiler/run_generator.py b/tb_plugin/torch_tb_profiler/profiler/run_generator.py index 738e611c6..03bdebc1e 100644 --- a/tb_plugin/torch_tb_profiler/profiler/run_generator.py +++ b/tb_plugin/torch_tb_profiler/profiler/run_generator.py @@ -35,10 +35,12 @@ def generate_run_profile(self): profile_run.views.append(consts.OP_VIEW) profile_run.operation_pie_by_name = self._generate_op_pie() + # pyrefly: ignore [bad-argument-type] profile_run.operation_table_by_name = self._generate_op_table(self.profile_data.op_list_groupby_name) profile_run.operation_stack_by_name = self._generate_op_table_for_stack(False) profile_run.operation_pie_by_name_input = self._generate_op_pie(True) profile_run.operation_table_by_name_input = self._generate_op_table( + # pyrefly: ignore [bad-argument-type] self.profile_data.op_list_groupby_name_input, True) profile_run.operation_stack_by_name_input = self._generate_op_table_for_stack(True) @@ -97,6 +99,7 @@ def build_avg_cost_dict(part_name: str, part_cost: float): cost_dict = {'name': part_name, 'description': '', 'value': round(part_cost), + # pyrefly: ignore [missing-attribute] 'extra': round(100 * part_cost / self.profile_data.avg_costs.costs[ProfileRole.Total], 2)} return cost_dict @@ -108,6 +111,7 @@ def build_avg_cost_dict(part_name: str, part_cost: float): data['steps'] = {} data['steps']['columns'] = [{'type': 'string', 'name': 'Step'}] if show_gpu: + # pyrefly: ignore [bad-argument-type] data['steps']['columns'].extend([{'type': 'number', 'name': 'Kernel'}, column_tootip, {'type': 'number', 'name': 'Memcpy'}, @@ -115,11 +119,14 @@ def build_avg_cost_dict(part_name: str, part_cost: float): {'type': 'number', 'name': 'Memset'}, column_tootip]) if self.profile_data.has_communication: + # pyrefly: ignore [bad-argument-type] data['steps']['columns'].extend([{'type': 'number', 'name': 'Communication'}, column_tootip]) if show_gpu: + # pyrefly: ignore [bad-argument-type] data['steps']['columns'].extend([{'type': 'number', 'name': 'Runtime'}, column_tootip]) + # pyrefly: ignore [bad-argument-type] data['steps']['columns'].extend([{'type': 'number', 'name': 'DataLoader'}, column_tootip, {'type': 'number', 'name': 'CPU Exec'}, @@ -128,8 +135,11 @@ def build_avg_cost_dict(part_name: str, part_cost: float): column_tootip]) data['steps']['rows'] = [] + # pyrefly: ignore [bad-argument-type] for i in range(len(self.profile_data.steps_costs)): + # pyrefly: ignore [unsupported-operation] costs = self.profile_data.steps_costs[i] + # pyrefly: ignore [unsupported-operation] step_name = self.profile_data.steps_names[i] row = [step_name] if show_gpu: @@ -156,25 +166,35 @@ def build_avg_cost_dict(part_name: str, part_cost: float): avg_costs = [] if show_gpu: avg_costs.extend([ + # pyrefly: ignore [missing-attribute] build_avg_cost_dict('Kernel', self.profile_data.avg_costs.costs[ProfileRole.Kernel]), + # pyrefly: ignore [missing-attribute] build_avg_cost_dict('Memcpy', self.profile_data.avg_costs.costs[ProfileRole.Memcpy]), + # pyrefly: ignore [missing-attribute] build_avg_cost_dict('Memset', self.profile_data.avg_costs.costs[ProfileRole.Memset]) ]) if self.profile_data.has_communication: avg_costs.extend([ + # pyrefly: ignore [missing-attribute] build_avg_cost_dict('Communication', self.profile_data.avg_costs.costs[ProfileRole.Communication]) ]) if show_gpu: avg_costs.extend([ + # pyrefly: ignore [missing-attribute] build_avg_cost_dict('Runtime', self.profile_data.avg_costs.costs[ProfileRole.Runtime]) ]) avg_costs.extend([ + # pyrefly: ignore [missing-attribute] build_avg_cost_dict('DataLoader', self.profile_data.avg_costs.costs[ProfileRole.DataLoader]), + # pyrefly: ignore [missing-attribute] build_avg_cost_dict('CPU Exec', self.profile_data.avg_costs.costs[ProfileRole.CpuOp]), + # pyrefly: ignore [missing-attribute] build_avg_cost_dict('Other', self.profile_data.avg_costs.costs[ProfileRole.Other]) ]) + # pyrefly: ignore [unsupported-operation] data['performance'] = [{'name': 'Average Step Time', 'description': '', + # pyrefly: ignore [missing-attribute] 'value': round(self.profile_data.avg_costs.costs[ProfileRole.Total]), 'extra': 100, 'children': avg_costs}] @@ -199,6 +219,7 @@ def _generate_op_pie(self, group_by_input_shape: bool = False): else: op_list = self.profile_data.op_list_groupby_name + # pyrefly: ignore [not-iterable] for op_agg in op_list: # Whether device_duration & self_device_duration are accurate or not depends on the input tracing data. if op_agg.device_duration > 0: @@ -223,28 +244,36 @@ def _generate_op_pie(self, group_by_input_shape: bool = False): if len(op_device_total_time) > 0: device_total_time['title'] = 'Device Total Time (us)' + # pyrefly: ignore [unsupported-operation] device_total_time['columns'] = [{'type': 'string', 'name': 'name'}, {'type': 'number', 'name': 'value'}] + # pyrefly: ignore [unsupported-operation] device_total_time['rows'] = op_device_total_time else: device_total_time = None if len(op_device_self_time) > 0: device_self_time['title'] = 'Device Self Time (us)' + # pyrefly: ignore [unsupported-operation] device_self_time['columns'] = [{'type': 'string', 'name': 'name'}, {'type': 'number', 'name': 'value'}] + # pyrefly: ignore [unsupported-operation] device_self_time['rows'] = op_device_self_time else: device_self_time = None if len(op_host_total_time) > 0: host_total_time['title'] = 'Host Total Time (us)' + # pyrefly: ignore [unsupported-operation] host_total_time['columns'] = [{'type': 'string', 'name': 'name'}, {'type': 'number', 'name': 'value'}] + # pyrefly: ignore [unsupported-operation] host_total_time['rows'] = op_host_total_time else: host_total_time = None if len(op_host_self_time) > 0: host_self_time['title'] = 'Host Self Time (us)' + # pyrefly: ignore [unsupported-operation] host_self_time['columns'] = [{'type': 'string', 'name': 'name'}, {'type': 'number', 'name': 'value'}] + # pyrefly: ignore [unsupported-operation] host_self_time['rows'] = op_host_self_time else: host_self_time = None @@ -286,14 +315,21 @@ def _generate_op_table(self, op_list: Iterable[OperatorAgg], group_by_input_shap row['name'] = op.name if group_by_input_shape: row['input_shape'] = op.input_shape + # pyrefly: ignore [unsupported-operation] row['calls'] = op.calls if show_gpu: + # pyrefly: ignore [unsupported-operation] row['device_self_duration'] = round(op.self_device_duration) + # pyrefly: ignore [unsupported-operation] row['device_total_duration'] = round(op.device_duration) + # pyrefly: ignore [unsupported-operation] row['host_self_duration'] = round(op.self_host_duration) + # pyrefly: ignore [unsupported-operation] row['host_total_duration'] = round(op.host_duration) row['tc_eligible'] = 'Yes' if op.tc_eligible else 'No' + # pyrefly: ignore [unsupported-operation] row['tc_self_ratio'] = round(100 * op.tc_self_ratio, 2) + # pyrefly: ignore [unsupported-operation] row['tc_total_ratio'] = round(100 * op.tc_total_ratio, 2) if call_stack: row['call_stack'] = op.callstacks.pop() @@ -302,6 +338,7 @@ def _generate_op_table(self, op_list: Iterable[OperatorAgg], group_by_input_shap key = op.name + '###' + str(op.input_shape) else: key = op.name + # pyrefly: ignore [not-iterable, unsupported-operation] row['has_call_stack'] = key in stack_list_dict data.append(row) @@ -314,6 +351,7 @@ def _generate_op_table_for_stack(self, group_by_input_shape: bool): stack_list_dict = self.profile_data.stack_lists_group_by_name result = dict() + # pyrefly: ignore [missing-attribute] for k, v in stack_list_dict.items(): result[k] = self._generate_op_table(v, group_by_input_shape, True) return result @@ -343,6 +381,7 @@ def _generate_kernel_op_table(self): table['columns'].extend(gpu_metrics_columns) table['rows'] = [] + # pyrefly: ignore [no-matching-overload] kernel_list: List[KernelAggByNameOp] = sorted( self.profile_data.kernel_list_groupby_name_op, key=lambda x: x.total_duration, reverse=True) for agg_by_name_op in kernel_list: @@ -363,6 +402,7 @@ def _generate_kernel_op_table(self): def _generate_kernel_pie(self): pie = {'columns': [{'type': 'string', 'name': 'name'}, {'type': 'number', 'name': 'value'}], 'rows': []} + # pyrefly: ignore [missing-attribute] for _id, (name, row) in enumerate(self.profile_data.kernel_stat.iterrows()): pie['rows'].append([name, row['sum']]) data = {'total': pie} @@ -394,6 +434,7 @@ def _generate_kernel_table(self): table['columns'].extend(gpu_metrics_columns) table['rows'] = [] + # pyrefly: ignore [missing-attribute] for _id, (name, row) in enumerate(self.profile_data.kernel_stat.iterrows()): kernel_row = [name, 'Yes' if row['tc_used'] else 'No'] for i, column in enumerate(columns): @@ -405,6 +446,7 @@ def _generate_kernel_table(self): def _generate_tc_pie(self): pie = {'columns': [{'type': 'string', 'name': 'name'}, {'type': 'number', 'name': 'value'}], 'rows': []} pie['rows'].append(['Using Tensor Cores', self.profile_data.tc_used_ratio]) + # pyrefly: ignore [unsupported-operation] pie['rows'].append(['Not Using Tensor Cores', 1.0 - self.profile_data.tc_used_ratio]) data = {'total': pie} return data @@ -496,9 +538,12 @@ def _generate_overlap_graph(self): steps_to_overlap['all'] = OrderedDict() for data in self.all_profile_data: steps_to_overlap['all'][data.worker] = [0, 0, 0, 0] + # pyrefly: ignore [bad-argument-type] step_number = len(data.steps_names) + # pyrefly: ignore [bad-argument-type] for i, step_name in enumerate(data.steps_names): steps_to_overlap.setdefault(step_name, OrderedDict()) + # pyrefly: ignore [unsupported-operation] costs = data.comm_overlap_costs[i] steps_to_overlap[step_name][data.worker] = [ costs.computation - costs.overlap, @@ -512,6 +557,7 @@ def _generate_overlap_graph(self): steps_to_overlap['all'][data.worker]] for k, v in steps_to_overlap.items(): steps_to_overlap[k] = OrderedDict(sorted(v.items())) + # pyrefly: ignore [unsupported-operation] result['data'] = steps_to_overlap return result @@ -527,7 +573,9 @@ def _generate_wait_graph(self): steps_to_wait['all'] = OrderedDict() for data in self.all_profile_data: steps_to_wait['all'][data.worker] = [0, 0] + # pyrefly: ignore [missing-attribute] step_number = len(data.step_comm_stats.values()) + # pyrefly: ignore [missing-attribute] for step, comm_stats in data.step_comm_stats.items(): steps_to_wait.setdefault(step, OrderedDict())[data.worker] = [ comm_stats[1], @@ -540,6 +588,7 @@ def _generate_wait_graph(self): for k, v in steps_to_wait.items(): steps_to_wait[k] = OrderedDict(sorted(v.items())) + # pyrefly: ignore [unsupported-operation] result['data'] = steps_to_wait return result @@ -563,6 +612,7 @@ def _generate_ops_table(self): for column in col_names: table['columns'].append({'type': 'number', 'name': column}) table['rows'] = [] + # pyrefly: ignore [missing-attribute] for op, stats in data.total_comm_stats.items(): row = [ op, @@ -576,5 +626,6 @@ def _generate_ops_table(self): ] table['rows'].append(row) workers_to_comm_ops[data.worker] = table + # pyrefly: ignore [no-matching-overload] result['data'] = OrderedDict(sorted(workers_to_comm_ops.items())) return result diff --git a/tb_plugin/torch_tb_profiler/profiler/trace.py b/tb_plugin/torch_tb_profiler/profiler/trace.py index 538a29246..9ec9d7557 100644 --- a/tb_plugin/torch_tb_profiler/profiler/trace.py +++ b/tb_plugin/torch_tb_profiler/profiler/trace.py @@ -119,6 +119,7 @@ class MemoryEvent(BaseEvent): def __init__(self, type, data): super().__init__(type, data) self.scope: str = data.get('s', '') + # pyrefly: ignore [bad-assignment] self.device_id: int = self.args.get('Device Id') dtype = self.args.get('Device Type') if dtype is not None: @@ -127,6 +128,7 @@ def __init__(self, type, data): except ValueError: dtype = None + # pyrefly: ignore [bad-assignment] self.device_type: DeviceType = dtype @property @@ -149,13 +151,16 @@ def total_reserved(self): class PythonFunctionEvent(DurationEvent): def __init__(self, type, data): super().__init__(type, data) + # pyrefly: ignore [bad-assignment] self.python_id: int = self.args.get('Python id') + # pyrefly: ignore [bad-assignment] self.python_parent_id: int = self.args.get('Python parent id') class ModuleEvent(PythonFunctionEvent): def __init__(self, data): super().__init__(EventTypes.MODULE, data) + # pyrefly: ignore [bad-assignment] self.module_id: int = self.args.get('Python module id') diff --git a/tb_plugin/torch_tb_profiler/run.py b/tb_plugin/torch_tb_profiler/run.py index 6400384d3..a1c40504c 100644 --- a/tb_plugin/torch_tb_profiler/run.py +++ b/tb_plugin/torch_tb_profiler/run.py @@ -119,14 +119,17 @@ def __init__(self, worker, span): self.overview = None self.operation_pie_by_name = None self.operation_table_by_name = None + # pyrefly: ignore [bad-assignment] self.operation_stack_by_name: Dict = None self.operation_pie_by_name_input = None self.operation_table_by_name_input = None + # pyrefly: ignore [bad-assignment] self.operation_stack_by_name_input: Dict = None self.kernel_op_table = None self.kernel_pie = None self.kernel_table = None self.tc_pie = None + # pyrefly: ignore [bad-assignment] self.trace_file_path: str = None self.gpu_metrics = None @@ -136,13 +139,18 @@ def __init__(self, worker, span): # for memory stats and curve self.memory_snapshot: Optional[MemorySnapshot] = None + # pyrefly: ignore [bad-assignment] self.tid2tree: Dict[int, OperatorNode] = None + # pyrefly: ignore [bad-assignment] self.pl_tid2tree: Dict[int, OperatorNode] = None + # pyrefly: ignore [no-matching-overload, not-a-type] self.module_stats: Optional[List(Stats)] = None + # pyrefly: ignore [no-matching-overload, not-a-type] self.pl_module_stats: Optional[List(Stats)] = None def append_gpu_metrics(self, raw_data: bytes): + # pyrefly: ignore [no-matching-overload] counter_json_str = '{}'.format(', '.join(self.gpu_metrics)) counter_json_bytes = bytes(counter_json_str, 'utf-8') @@ -182,6 +190,7 @@ def get_memory_stats(self, start_ts=None, end_ts=None, memory_metric='K'): cano = Canonicalizer(memory_metric=memory_metric) round = DisplayRounder(ndigits=2) + # pyrefly: ignore [missing-attribute] stats = self.memory_snapshot.get_memory_statistics(self.tid2tree, start_ts=start_ts, end_ts=end_ts) result = { @@ -489,7 +498,6 @@ def traverse_node(parent: List, node: OperatorNode): } parent.append(d) for child in node.children: - # pyre-fixme[6]: For 1st argument expected `List[typing.Any]` but # got `Union[List[typing.Any], int, str]`. traverse_node(d['children'], child) traverse_node(result, root) diff --git a/tb_plugin/torch_tb_profiler/utils.py b/tb_plugin/torch_tb_profiler/utils.py index 821883d99..b4a95ef19 100644 --- a/tb_plugin/torch_tb_profiler/utils.py +++ b/tb_plugin/torch_tb_profiler/utils.py @@ -114,17 +114,18 @@ def __call__(self, v: float): return round(v, ndigit) +# pyrefly: ignore [no-matching-overload] @contextmanager +# pyrefly: ignore [bad-return] def timing(description: str, force: bool = False) -> None: if force or os.environ.get('TORCH_PROFILER_BENCHMARK', '0') == '1': start = time.time() - # pyre-fixme[7]: Expected `None` but got `Generator[None, typing.Any, # typing.Any]`. yield elapsed_time = time.time() - start + # pyrefly: ignore [missing-attribute] logger.info(f'{description}: {elapsed_time}') else: - # pyre-fixme[7]: Expected `None` but got `Generator[None, typing.Any, # typing.Any]`. yield