1. 24 Jun, 2022 3 commits
    • Yanghan Wang's avatar
      better organize builtin runner's default config · 07eb7a1e
      Yanghan Wang authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/313
      
      It's not natural to put runner's default config functions under `d2go/utils/`, move them to `d2go/runner/config_defaults.py` and clean things up. This also reduce the inter-sub-package dependencies.
      
      Reviewed By: mattcyu1
      
      Differential Revision: D37407078
      
      fbshipit-source-id: 432644bee4f12306a14bac3dba76ced08b3683aa
      07eb7a1e
    • Mik Vyatskov's avatar
      Only save results to file from rank 0 · f0297b81
      Mik Vyatskov authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/309
      
      Right now multiple machines can try to write to the same output file,
      since they get the same argument. Additionally, on the same machine, several
      outputs can be saved which requires unncessary unpacking. This change makes
      train_net only write output of the rank 0 trainer.
      
      Reviewed By: wat3rBro
      
      Differential Revision: D37310084
      
      fbshipit-source-id: 9d5352a274e8fb1d2043393b12896d402333c17b
      f0297b81
    • Yanghan Wang's avatar
      use runner class instead of instance outside of main · 8051775c
      Yanghan Wang authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/312
      
      As discussed, we decided to not use runner instance outside of `main`, previous diffs already solved the prerequisites, this diff mainly does the renaming.
      - Use runner name (str) in the fblearner, ML pipeline.
      - Use runner name (str) in FBL operator, MAST and binary operator.
      - Use runner class as the interface of main, it can be either the name of class (str) or actual class. The main usage should be using `str`, so that the importing of class happens inside `main`. But it's also a common use case to import runner class and call `main` for things like ad-hoc scripts or tests, supporting actual class makes it easier modify code for those cases (eg. some local test class doesn't have a name, so it's not feasible to use runner name).
      
      Reviewed By: newstzpz
      
      Differential Revision: D37060338
      
      fbshipit-source-id: 879852d41902b87d6db6cb9d7b3e8dc55dc4b976
      8051775c
  2. 22 Jun, 2022 2 commits
  3. 21 Jun, 2022 2 commits
  4. 20 Jun, 2022 1 commit
  5. 18 Jun, 2022 2 commits
  6. 17 Jun, 2022 3 commits
  7. 16 Jun, 2022 8 commits
    • Yanghan Wang's avatar
      support for using config file with _DEFAULTS_ via cli · 521b3cad
      Yanghan Wang authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/271
      
      - set `get_default_cfg = None` to opt-in this new feature.
      - support config with `_DEFAULTS_` when loading config file. Note that we don't check explicitly `"_DEFAULTS_" in config file` but check `runner.get_default_cfg == None`, this is because runner having `get_default_cfg` and config having `_DEFAULTS_` should be mutually exclusive, and `load_full_config_from_file` can raise proper error if `_DEFAULTS_` is missing.
      - we also need to save `_DEFAULTS_` in the diff config.
      
      Reviewed By: tglik
      
      Differential Revision: D36868581
      
      fbshipit-source-id: e0e19309c3df5a85383ce1454b321a68d0868dc4
      521b3cad
    • Yanghan Wang's avatar
      restructure lightning related code · 318a3d79
      Yanghan Wang authored
      Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/237
      
      Reviewed By: tglik
      
      Differential Revision: D35954531
      
      fbshipit-source-id: b69c8065928fe385d29f20f2c2460d60d63fca00
      318a3d79
    • Matthew Yu's avatar
      add modeling hook algo and helper · f3fc01aa
      Matthew Yu authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/299
      
      This implements the first iteration of generalized distillation in D2 (https://github.com/facebookresearch/d2go/commit/87374efb134e539090e0b5c476809dc35bf6aedb)Go. The functionality is separated into the following:
      
      => Adding distillation functionality without user changing their meta architecture:
      
      class DistillationModelingHook
      * This is an implementation detail that we hide from the user.
      * We use dynamic mixin to specify additional functionality to the user's model. In this way, the original (student) model retains all attributes but the mixin class will override the forward (and provide more functionality like teacher updates).
      * Teacher build currently only supports loading a torchscript model, pytorch compatiblity in later diffs
      
      => Implementing distillation methods
      
      class DistillationAlgorithm
      * The user can use some default algorithm (e.g., LabelDistillation) or create their own. This is where we specify the overrided forward func of the model and any other distillation requirements (updating the weights of the teacher model).
      * The basic LabelDistillation allows a user to use a teacher model during training to relabel the gt
      
      => User customization
      
      class DistillationHelper
      * This is what we expect the user to customize. As an example the user probably needs to write their own pseudo_labeler to take batched_inputs and relabel this with the teacher
      
      Both DistillationHelper and DistillationAlgorithm use a registry so that users can add their customization in their own code and use these customizations by specifying in the config
      
      Reviewed By: newstzpz
      
      Differential Revision: D36708227
      
      fbshipit-source-id: bc427c5d42d0c7ff4d839bf10782efac24dea107
      f3fc01aa
    • Miquel Jubert Hermoso's avatar
      Hardcode top-level directory, remove import for resource access · ce776f7d
      Miquel Jubert Hermoso authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/229
      
      *This diff is part of a stack which has the goal of "buckifying" D2 (https://github.com/facebookresearch/d2go/commit/87374efb134e539090e0b5c476809dc35bf6aedb)Go core and enabling autodeps and other tooling. The last diff in the stack introduces the TARGETS. The diffs earlier in the stack are resolving circular dependencies and other issues which prevent the buckification from occurring.*
      
      This diff changes the import paths being rerouted in the d2go package. Instead of local-importing the package, which creates a buck circular dependency, we can hardcode the top-level path. We know it is fixed because we are defining it with base_module.
      
      For the other packages it can remain as-is.
      
      Also add some dependencies annotations in preparation for the buckification, with manual.
      
      Reviewed By: wat3rBro
      
      Differential Revision: D35928513
      
      fbshipit-source-id: 756c95740bab519e8093d254bcee64692e1a1b98
      ce776f7d
    • Mik Vyatskov's avatar
      Implement a central helper for converting arguments to CLI args · 3b64e76a
      Mik Vyatskov authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/301
      
      This is a follow-up of earlier work to extract part responsible for the
      centrally defined parameters from the helper in train_net closer to where the
      parameters are defined.
      
      Reviewed By: tglik
      
      Differential Revision: D37176212
      
      fbshipit-source-id: 226415f36f4872ac3d9ba41541b4389a18cc11e6
      3b64e76a
    • Mircea Cimpoi's avatar
      Refactor quantization logic to separate function · 5654d831
      Mircea Cimpoi authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/296
      
      Extract the model quantization logic to separate function.
      +minor cleanup (remove unused imports, f-strings)
      
      Reviewed By: wat3rBro
      
      Differential Revision: D36999434
      
      fbshipit-source-id: 7aad64921b8cdf8779527c19b077ee788403c6b8
      5654d831
    • Yanghan Wang's avatar
      make launch return results from all ranks · 55dc3da1
      Yanghan Wang authored
      Summary:
      X-link: https://github.com/facebookresearch/mobile-vision/pull/86
      
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/300
      
      Similar to `elastic_launch`, make `launch` return results for all ranks, this is beneficial for cases where each rank having different return value`.
      
      There'll be some test failing for V1, it'll help finding related callsites.
      
      Reviewed By: tglik
      
      Differential Revision: D37016935
      
      fbshipit-source-id: eb989342c0ddd642c8369b5dddfa8aac8cb38917
      55dc3da1
    • Shiyu Dong's avatar
      Add CallFuncWithNameAndJsonFile · d6a966fd
      Shiyu Dong authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/288
      
      Add a new call function to handle adhoc datasets that needs to be called with dataset_name. This is mainly to handle the incompatibility of `extend_coco_load` function with AdhocDataset
      
      For example,
      * if we choose to register `extend_coco_load` function as CallFuncWithJsonFile, AdhocDataset will register the same function, while failed to update the `dataset_name` argument passed to `extended_coco_load`.
      
      * If we choose to register `extend_coco_load` function normally, we couldn't use the `LOAD_KWARGS` that specifies additional fields like `image_direct_copy_keys` when register AdhocDatasets
      
      Therefore adding the new function allows to update register function with specifying new json as well as new dataset_name in the same time.
      
      Reviewed By: sstsai-adl
      
      Differential Revision: D37100742
      
      fbshipit-source-id: 93f4a7ac23f95812aca80c40872b15f92d449da0
      d6a966fd
  8. 15 Jun, 2022 4 commits
  9. 14 Jun, 2022 4 commits
    • Yanghan Wang's avatar
      make get_default_cfg a classmethod · 65dad512
      Yanghan Wang authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/293
      
      In order to pass runner during the workflow using "runner name" instead of runner instance, we need to make sure the `get_default_cfg` is not instance method. It can be either staticmethod or classmethod, but I choose classmethod for better inheritance.
      
      code mode using following script:
      ```
      #!/usr/bin/env python3
      
      import json
      import os
      import subprocess
      
      result = subprocess.check_output("fbgs --json 'def get_default_cfg('", shell=True)
      fbgs = json.loads(result)
      fbsource_root = os.path.expanduser("~")
      
      def _indent(s):
          return len(s) - len(s.lstrip())
      
      def resolve_instance_method(content):
          lines = content.split("\n")
          for idx, line in enumerate(lines):
              if "def get_default_cfg(self" in line:
                  indent = _indent(line)
                  # find the class
                  for j in range(idx, 0, -1):
                      if lines[j].startswith(" " * (indent - 4) + "class "):
                          class_line = lines[j]
                          break
                  else:
                      raise RuntimeError("Can't find class")
                  print("class_line: ", class_line)
                  if "Runner" in class_line:
                      # check self if not used
                      for j in range(idx + 1, len(lines)):
                          if _indent(lines[j]) < indent:
                              break
                          assert "self" not in lines[j], (j, lines[j])
                      # update the content
                      assert "def get_default_cfg(self)" in line
                      lines[idx] = lines[idx].replace(
                          "def get_default_cfg(self)", "def get_default_cfg(cls)"
                      )
                      lines.insert(idx, " " * indent + "classmethod")
                      return "\n".join(lines)
          return content
      
      def resolve_static_method(content):
          lines = content.split("\n")
          for idx, line in enumerate(lines):
              if "def get_default_cfg()" in line:
                  indent = _indent(line)
                  # find the class
                  for j in range(idx, 0, -1):
                      if "class " in lines[j]:
                          class_line = lines[j]
                          break
                  else:
                      print("[WARNING] Can't find class!!!")
                      continue
                  if "Runner" in class_line:
                      # check staticmethod is used
                      for j in range(idx, 0, -1):
                          if lines[j] == " " * indent + "staticmethod":
                              staticmethod_line_idx = j
                              break
                      else:
                          raise RuntimeError("Can't find staticmethod")
                      # update the content
                      lines[idx] = lines[idx].replace(
                          "def get_default_cfg()", "def get_default_cfg(cls)"
                      )
                      lines[staticmethod_line_idx] = " " * indent + "classmethod"
                      return "\n".join(lines)
          return content
      
      for result in fbgs["results"]:
          filename = os.path.join(fbsource_root, result["file_name"])
          print(f"processing: {filename}")
          with open(filename) as f:
              content = f.read()
          orig_content = content
          while True:
              old_content = content
              content = resolve_instance_method(content)
              content = resolve_static_method(content)
              if content == old_content:
                  break
          if content != orig_content:
              print("Updating ...")
              with open(filename, "w") as f:
                  f.write(content)
      ```
      
      Reviewed By: tglik
      
      Differential Revision: D37059264
      
      fbshipit-source-id: b09d5518f4232de95d8313621468905cf10a731c
      65dad512
    • Yanghan Wang's avatar
      support diff config for lightning_train_net · 8cf2b879
      Yanghan Wang authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/285
      
      `setup_after_launch` can now take `DefaultTask` as well (the `runner_or_task` can still be `None`, for runner-less train_net).
      
      Reviewed By: tglik
      
      Differential Revision: D37011560
      
      fbshipit-source-id: ce8a88242df0a16de8da97d94e8eb7def524c69c
      8cf2b879
    • Sam Tsai's avatar
      separating out save function and checking if it has been run previously for a dataset · 84dac84f
      Sam Tsai authored
      Summary:
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/282
      
      Writing the of the converted coco file needs to be synced since the file is used by COCOEval. The whole function could be called multiple times by main thread so need to add additional checks to see if dataset has been previous called.
      
      Reviewed By: wat3rBro
      
      Differential Revision: D36957778
      
      fbshipit-source-id: 5f9c5c038c13cbe24132ef1b44f6e94d5a26b66a
      84dac84f
    • Yanghan Wang's avatar
      fix DDP argument misalignment · 38958fcc
      Yanghan Wang authored
      Summary:
      X-link: https://github.com/facebookresearch/mobile-vision/pull/83
      
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/292
      
      Reviewed By: tglik, newstzpz
      
      Differential Revision: D37116726
      
      fbshipit-source-id: 9956fe19916521b4fb512207512861afe4f09148
      38958fcc
  10. 13 Jun, 2022 2 commits
  11. 10 Jun, 2022 3 commits
  12. 09 Jun, 2022 1 commit
  13. 08 Jun, 2022 1 commit
    • Yanghan Wang's avatar
      making bootstrap more robust · 1f45cf04
      Yanghan Wang authored
      Summary:
      X-link: https://github.com/facebookresearch/mobile-vision/pull/81
      
      Pull Request resolved: https://github.com/facebookresearch/d2go/pull/283
      
      - add `MoreMagicMock`, which handles inheritance and comparison.
      - also support lazy registering mocked objects (has to be `MoreMagicMock`).
      - don't need to skip `skip files that doesn't contain ".register()" call` since we can handle most files pretty well now.
      - also mock the open
      - delay the import for `from detectron2.utils.testing import assert_instances_allclose`; for some reason python is doing magic things if you import anything starting with `assert`, so the mocked import doesn't work.
      - makes log function nicer.
      
      Reviewed By: tglik
      
      Differential Revision: D36798327
      
      fbshipit-source-id: ccda7e7583b95a24f3dde1bbe0468593dacb8663
      1f45cf04
  14. 07 Jun, 2022 1 commit
  15. 06 Jun, 2022 3 commits