class_docstr: Measures the latency, number of estimated floating-point operations and parameters of each module in a PyTorch model.
  
  The flops-profiler profiles the forward pass of a PyTorch model and prints the model graph with the measured profile attached to each module. It shows how latency, flops and parameters are spent in the model and which modules or layers could be the bottleneck. It also outputs the names of the top k modules in terms of aggregated latency, flops, and parameters at depth l with k and l specified by the user. The output profile is computed for each batch of input.
  The DeepSpeed flops profiler can be used with the DeepSpeed runtime or as a standalone package.
  When using DeepSpeed for model training, the flops profiler can be configured in the deepspeed_config file and no user code change is required.
  
  If using the profiler as a standalone package, one imports the flops_profiler package and use the APIs.
  
  Here is an example for usage in a typical training workflow:
  
      .. code-block:: python
  
          model = Model()
          prof = FlopsProfiler(model)
  
          for step, batch in enumerate(data_loader):
              if step == profile_step:
                  prof.start_profile()
  
              loss = model(batch)
  
              if step == profile_step:
                  flops = prof.get_total_flops(as_string=True)
                  params = prof.get_total_params(as_string=True)
                  prof.print_model_profile(profile_step=profile_step)
                  prof.end_profile()
  
              loss.backward()
              optimizer.step()
  
  To profile a trained model in inference, use the `get_model_profile` API.
  
  Args:
      object (torch.nn.Module): The PyTorch model to profile.
class_docstr_tok: ["Measures","the","latency",",","number","of","estimated","floating-point","operations","and","parameters","of","each","module","in","a","PyTorch","model",".","The","flops-profiler","profiles","the","forward","pass","of","a","PyTorch","model","and","prints","the","model","graph","with","the","measured","profile","attached","to","each","module",".","It","shows","how","latency",",","flops","and","parameters","are","spent","in","the","model","and","which","modules","or","layers","could","be","the","bottleneck",".","It","also","outputs","the","names","of","the","top","k","modules","in","terms","of","aggregated","latency",",","flops",",","and","parameters","at","depth","l","with","k","and","l","specified","by","the","user",".","The","output","profile","is","computed","for","each","batch","of","input",".","The","DeepSpeed","flops","profiler","can","be","used","with","the","DeepSpeed","runtime","or","as","a","standalone","package",".","When","using","DeepSpeed","for","model","training",",","the","flops","profiler","can","be","configured","in","the","deepspeed_config","file","and","no","user","code","change","is","required",".","If","using","the","profiler","as","a","standalone","package",",","one","imports","the","flops_profiler","package","and","use","the","APIs",".","Here","is","an","example","for","usage","in","a","typical","training","workflow",":","..","code-block",":",":","python","model","=","Model","(",")","prof","=","FlopsProfiler","(","model",")","for","step",",","batch","in","enumerate","(","data_loader",")",":","if","step","==","profile_step",":","prof.start_profile","(",")","loss","=","model","(","batch",")","if","step","==","profile_step",":","flops","=","prof.get_total_flops","(","as_string=True",")","params","=","prof.get_total_params","(","as_string=True",")","prof.print_model_profile","(","profile_step=profile_step",")","prof.end_profile","(",")","loss.backward","(",")","optimizer.step","(",")","To","profile","a","trained","model","in","inference",",","use","the","`","get_model_profile","`","API",".","Args",":","object","(","torch.nn.Module",")",":","The","PyTorch","model","to","profile","."]
docstr: Ends profiling.
  
  The added attributes and handles are removed recursively on all the modules.
docstr_tok: ["Ends","profiling",".","The","added","attributes","and","handles","are","removed","recursively","on","all","the","modules","."]
code: def end_profile(self):
      """Ends profiling.
  
      The added attributes and handles are removed recursively on all the modules.
      """
      if not self.started:
          return
      self.stop_profile()
      self.started = False
  
      def remove_profile_attrs(module):
          if hasattr(module, "__flops__"):
              del module.__flops__
          if hasattr(module, "__macs__"):
              del module.__macs__
          if hasattr(module, "__params__"):
              del module.__params__
          if hasattr(module, "__start_time__"):
              del module.__start_time__
          if hasattr(module, "__duration__"):
              del module.__duration__
  
      self.model.apply(remove_profile_attrs)
  
imports: import time
  import torch
  import torch.nn
  import torch.nn.functional
  from functools import partial
  from typing import List, Optional
  from collections import OrderedDict
  import numpy
label_desc: Use image node_id 5 for calling the FlopsProfiler obj's underlying member method code with example usage: obj.end_profile() without return types