- 14 Jan, 2023 1 commit
-
-
Salil Desai authored
Summary: X-link: https://github.com/pytorch/pytorch/pull/92081 Pull Request resolved: https://github.com/facebookresearch/d2go/pull/459 Reland of D41690203 (https://github.com/facebookresearch/d2go/commit/18de6ffb19037e8ea11057515cc3d6d966a6e799) Remove MobileOptimizerType and all rewrite flags from torch.X and torch._C.X to clean up torch.X and torch._C.X namespaces The affected rewrite flags are - CONV_BN_FUSION - FUSE_ADD_RELU - HOIST_CONV_PACKED_PARAMS - INSERT_FOLD_PREPACK_OPS - REMOVE_DROPOUT - VULKAN_AUTOMATIC_GPU_TRANSFER Bc-Breaking Change: Before this change, the rewrite flags were accessible through all of 1. torch.utils.mobile_optimizer.MobileOptimizerType.X 2. torch._C.MobileOptimizerType.X 3. torch.X 4. torch.MobileOptimizerType.X 5. torch._C.X But after this change, only torch.utils.mobile_optimizer.MobileOptimizerType.X (option 1 above) and the newly added torch._C._MobileOptimizerType.X remain Corresponding updates to PyTorch Tutorial Docs are in https://github.com/pytorch/tutorials/pull/2163 Reviewed By: SS-JIA Differential Revision: D42442395 fbshipit-source-id: 14500b3667f541fd1ec85b1624125120176c6fd0
-
- 13 Jan, 2023 4 commits
-
-
Anthony Chen authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/458 Make AMP compatible with FSDP. FSDP does not depend on the torch AMP module and implements its own MixedPrecision module. This MixedPrecision module directly saves additional copy of weights in lower precision and use run these tensors in mixed precision training. This is very different from AMP, which automatically casts tensors to lower precision upon tensor operations. This diff solves some compatibility bugs between AMP and FSDP with 2 changes: 1. Use "never_wrap_policy" as the default dummy autowrap policy. FSDP Mixed Precision doesn't work with Batchnorm layers. This is because FSDP and other resources like NVidia apex highly discourage running lower precision for batchnorm: https://github.com/pytorch/pytorch/issues/75478. We need to use some autowrap policy in order to let FSDP surpass batchnorm layers in constructing mixed precision. 2. Wrap FSDPWrapper.forward() with autocast() FSDP Mixed Precision uses lower-precision tensors in computation, which could raise type mismatch error when amp.autocast() is not enabled, like in eval. Thus, we wrap FSDP forward() with autocast() Reviewed By: wat3rBro Differential Revision: D41328834 fbshipit-source-id: 18cf94c4ad8d9422ffd3bb335873cd29ac987ae9
-
Anthony Chen authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/446 ## Design Following D41861308, local checkpoints need to be converted to global ones before being loaded and used in non-FSDP wrapped models. This diff implements such conversion in d2go checkpointer level to allow automatic conversion with minimal user interference and no new config key. In previous diff, `FSDPWrapper` has 2 loading modes and 2 saving modes: it uses `load_local_state_dict` to determine whether the ckpt we want to load is local or global, and uses `use_local_state_dict` to decide whether to save new ckpts as local or global. Thus, there are 4 combinations of loading/saving modes: 1. load local + save local 2. load local + save global 3. load global + save local 4. load global + save global And the local-to-global checkpoint conversion maps to mode 2: load local + save global. Thus, when the checkpointer is in mode 2, it automatically saves the model to a global ckpt right after it loads the local ckpt. Because this happens in checkpointer level, normal training/eval can resume after ckpt conversion. This gives users a consistent and seamless experience with normal training/eval, while also providing a separate ckpt conversion feature via eval-only. ## Usage Suppose we want to convert local checkpoint `/tmp/model_final`, user can run the same training command with extra args: `MODEL.WEIGHTS=/tmp/model_final` and `FSDP.USE_LOCAL_STATE_DICT=False` Wiki: https://www.internalfb.com/intern/wiki/Mobile_Vision/Detectron2Go/D2 (https://github.com/facebookresearch/d2go/commit/87374efb134e539090e0b5c476809dc35bf6aedb)Go_Tutorials/Diffusion_Pipeline/Diffusion_Model_Inference/#using-checkpoints-traine Reviewed By: wat3rBro Differential Revision: D41926662 fbshipit-source-id: 18a62607a79b0e917d929e9ea85ac1658fb895ca
-
Anthony Chen authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/457 ## Context: The Pytorch FSDP (Fully Sharded Data Parallel) backend supports two checkpointing modes. The first one is full_state_dict mode, where each FSDP worker summons parameters from other workers to produce a global state dict that can be loaded by non-FSDP models. This mode is the desired mode for checkpointing because checkpoint structures and key names follows the default convention. It's already supported in D39228316 (https://github.com/facebookresearch/d2go/commit/02625ff83207b836df349eadc4a61eb3d4a5810c) However, when the model is too large to fit into a single GPU memory, this approach would fail because a worker's GPU can't hold all the summoned parameters during checkpoint saving. The rescue is to use the second checkpointing mode: local_state_dict. This mode saves the sharded parameters in each GPU process locally. It can only be loaded by FSDP-wrapped models with the same distributed training settings (i.e. num processes), but it reduces the need for summoning parameters and greatly saves peak GPU memory during training This diff enables local state dict checkpointing in d2go. ## API: This diff supports both **saving** local state and **loading** state dict that is locally sharded. Whether to save local state is controlled by `FSDP.USE_LOCAL_STATE`. If `FSDP.USE_LOCAL_STATE=True` and we want to save `output/model_0000001.pth` as in the old pattern, the local checkpoints will be saved as: ``` - output - model_0000001 - rank0.pth - rank1.pth - rank2.pth - rank3.pth ``` Whether to load local state, on the other hand, is controlled by the path of the checkpoint to load. If the path is a file, i.e. `output/model_final.pth`, the file will be loaded as a full state dict by all GPU processes like before. If the path is a directory, i.e. `output/model_final`, the checkpointer will attempt to load `output/model_final/rankX.pth` for rank X. This API design enables the full combinations of loading local/full states and saving local/full states. ## Conversion to full state dict [Temporary] Conversion from local state dict to full state dict is needed during an e2e workflow. This will be implemented in another diff Reviewed By: wat3rBro Differential Revision: D41861308 fbshipit-source-id: 2e01b601683d06b46f0c5517c6cff30bbcffa8f7
-
Anthony Chen authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/440 Move FSDP wrapping to runner.build_model by rewriting it as a modeling hook **Motivation** When a model is too large to run inference on a single GPU, it requires using FSDP with local checkpointing mode to save peak GPU memory. However, in eval_pytorch workflow (train_net with eval-only), models are evaluated without being wrapped by FSDP. This may cause OOM errors for the reasons above. Thus, it may be a better practice to wrap model with FSDP during `runner.build_model(cfg)`, so evaluation can also be run in the same FSDP setting as in training. This diff moves FSDP wrapping to `runner.build_model(cfg)` by rewriting it as a modeling hook. **API changes** * Users need to append `"FSDPModelingHook"` to `MODEL.MODELING_HOOKS` to enable FSDP. * `FSDP.ALGORITHM` can only be `full` or `grad_optim` **Note** It's not possible to unwrap an FSDP model back to the normal model, so FSDPModelingHook.unapply() can't be implemented Reviewed By: wat3rBro Differential Revision: D41416917 fbshipit-source-id: f3fc72d574cc6ccbe0d238e48c575926ba5b4d06
-
- 10 Jan, 2023 2 commits
-
-
Danylo Baibak authored
Differential Revision: D41690203 (https://github.com/facebookresearch/d2go/commit/18de6ffb19037e8ea11057515cc3d6d966a6e799) Original commit changeset: d901bdcbd16a Original Phabricator Diff: D41690203 (https://github.com/facebookresearch/d2go/commit/18de6ffb19037e8ea11057515cc3d6d966a6e799) fbshipit-source-id: bba9a29d5c2b6b69423160726d29c44843023fb0
-
Salil Desai authored
Summary: X-link: https://github.com/pytorch/pytorch/pull/91600 Pull Request resolved: https://github.com/facebookresearch/d2go/pull/452 bypass-github-export-checks Remove MobileOptimizerType and all rewrite flags from torch.X and torch._C.X to clean up torch.X and torch._C.X namespaces The affected rewrite flags are - CONV_BN_FUSION - FUSE_ADD_RELU - HOIST_CONV_PACKED_PARAMS - INSERT_FOLD_PREPACK_OPS - REMOVE_DROPOUT - VULKAN_AUTOMATIC_GPU_TRANSFER Bc-Breaking Change: Before this change, the rewrite flags were accessible through all of 1. torch.utils.mobile_optimizer.MobileOptimizerType.X 2. torch._C.MobileOptimizerType.X 3. torch.X 4. torch.MobileOptimizerType.X 5. torch._C.X But after this change, only torch.utils.mobile_optimizer.MobileOptimizerType.X (option 1 above) and the newly added torch._C._MobileOptimizerType.X remain Corresponding updates to PyTorch Tutorial Docs are in https://github.com/pytorch/tutorials/pull/2163 Reviewed By: kimishpatel Differential Revision: D41690203 fbshipit-source-id: d901bdcbd16a594c3268e09b57c61b38c33a562f
-
- 05 Jan, 2023 3 commits
-
-
Anthony Chen authored
Summary: X-link: https://github.com/facebookresearch/detectron2/pull/4667 X-link: https://github.com/fairinternal/detectron2/pull/578 Pull Request resolved: https://github.com/facebookresearch/d2go/pull/411 Add config option `cfg.LOAD_CKPT_TO_GPU` to load checkpoints to the worker's current GPU Previously, D2 (https://github.com/facebookresearch/d2go/commit/87374efb134e539090e0b5c476809dc35bf6aedb)go maps checkpoints to CPU before loading them to the model. In large-scale distributed training, many GPU processes may be used to train a model. This means each process will load the model checkpoint to a single CPU, causing the same model checkpoint to be loaded many times. This would cause CPU OOM issue when the model checkpoint size is large. There're two solutions to this problem. One is to load checkpoints to GPU; the other one is to use share memory for the checkpoint between different GPU processes. This diff implements the first solution, which can support cases where model size + model checkpoint size is smaller than the total GPU memory. The second solution may be revisited for large models that need to offload checkpoints to cpu. Reference diff: D40789062 Reviewed By: mcimpoi Differential Revision: D41063306 fbshipit-source-id: edcfd390a25582fffb2f1a6a7fc22917874ee2fc
-
Yanghan Wang authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/456 `3.20.1` version has security issue, as https://github.com/facebookresearch/d2go/security/dependabot/1.`3.20.x+` has previously known compatibility issue, thus pin the version to `3.20.2`. Reviewed By: YanjunChen329 Differential Revision: D42353218 fbshipit-source-id: 172d3a2d53f0c46326e0ae730ad0a96b33b8bade
-
Yanghan Wang authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/455 The test can be flaky due to numerical mismatch if using `self.AssertEqual`, eg. https://www.internalfb.com/intern/testinfra/diagnostics/1688850007977704.562950031998292.1672749571/ ``` Traceback (most recent call last): File "/data/sandcastle/boxes/eden-trunk-hg-fbcode-fbsource/buck-out/v2/gen/fbcode/104a4d5c3a690252/mobile-vision/d2go/tests/__modeling_test_modeling_distillation__/modeling_test_modeling_distillation#link-tree/d2go/tests/modeling/test_modeling_distillation.py", line 674, in test_da_train self.assertEqual( AssertionError: {'rea[14 chars]2894], grad_fn=<MulBackward0>), 'synthetic': t[85 chars]d0>)} != {'rea[14 chars]2894]), 'synthetic': tensor([1.4532]), 'add': [13 chars]64])} - {'add': tensor([18.0064], grad_fn=<MulBackward0>), - 'real': tensor([0.2894], grad_fn=<MulBackward0>), - 'synthetic': tensor([1.4532], grad_fn=<MulBackward0>)} + {'add': tensor([18.0064]), + 'real': tensor([0.2894]), + 'synthetic': tensor([1.4532])} ``` .Change to use `torch.testing.assert_close` instead for tensor comparison. Reviewed By: YanjunChen329 Differential Revision: D42352509 fbshipit-source-id: 8a647685d1347a9bd493f2faed7e066eb9159e14
-
- 04 Jan, 2023 1 commit
-
-
Yanghan Wang authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/453 Previous diffs updated the LRScheduler to public version (eg. https://github.com/facebookresearch/detectron2/pull/4709), this also requires newer version of pytorch-lightning. This diff upgrades the lightning version to 1.8.6, also fixes some deprecated call sites of old lightning versions. - `deepcopy` seems to be supported now, remove `_deepcopy` (there's now not allowed to access `trainer` attributed when it is `None`) - `dataloader_idx` is removed from `on_train_batch_start`. - stop using `_accelerator_connector` (the AcceleratorConnector doesn't have those attributes anymore). - deprecated `on_pretrain_routine_end` -> `on_fit_start` Reviewed By: YanjunChen329 Differential Revision: D42319019 fbshipit-source-id: ba46abbd98da96783e15d187a361fda47dc7d4d6
-
- 20 Dec, 2022 1 commit
-
-
Manuel Lopez Antequera authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/447 The first instance of each toy dataset was ignored when running cocoeval (null instance ids in the gt are not counted). See https://github.com/cocodataset/cocoapi/blob/master/PythonAPI/pycocotools/cocoeval.py#L39 Reviewed By: wat3rBro Differential Revision: D42080839 fbshipit-source-id: df5c758ba0a858a514c6d4a3c68d659b5b7220e5
-
- 19 Dec, 2022 4 commits
-
-
Yanghan Wang authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/450 move checking logic into `import_runner`, simplfy `_is_lightning_task` Reviewed By: mcimpoi Differential Revision: D42105853 fbshipit-source-id: 5fd51865a01f2cbac38aaedcac49207c26172ab9
-
Haroun Habeeb authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/438 Adding new fields to a config is only allowed if `new_allowed=True`. yacs `CfgNode` provides a `set_new_allowed(value: bool)` function. We create a context manager like `temp_defrost` but for new_allowed to use it. We also implement unit test for the same Reviewed By: yanglinfang, newstzpz, wat3rBro Differential Revision: D41748992 fbshipit-source-id: 71d048511476001ca96e6b36dde4d177b11268d7
-
Yanghan Wang authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/449 separate TestNetOutput and TrainNetOutput - update d2go binaries - update operators / workflows Reviewed By: mcimpoi Differential Revision: D42103714 fbshipit-source-id: 53f318c79d7339fb6fcfc3486e8b9cf249a598bf
-
Anton Rigner authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/437 # Problem - We use `TRAIN_CATEGORIES` to overrider the classes for convenient experimentation, to not have to re-map the JSON file - But it's not possible to use the WeightedTrainingSampler with specified repeat factors (`DATASETS.TRAIN_REPEAT_FACTOR`) when also overriding the classes to use for training (ad-hoc datasets), because the underlying dataset name doesn't match the datasets specified in the `TRAIN_REPEAT_FACTOR` pairs (mapping between <dataset_name, repeat_factor>) # Fix - Update the dataset names for the REPEAT_FACTORS mapping as well, if we have enabled the `WeightedTrainingSampler` and use ad-hoc datasets. Reviewed By: wat3rBro Differential Revision: D41765638 fbshipit-source-id: 51dad484e4d715d2de900b5d0b7c7caa19903fb7
-
- 16 Dec, 2022 1 commit
-
-
Francisc Bungiu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/448 Tracing d2go runners with using adamw optimizer yielded small operators being executed in the optimizer code. They can be fused together by using the foreach version. QPS gain is ~4.5%. Reviewed By: miqueljubert Differential Revision: D42004110 fbshipit-source-id: 807e0a297bb0b4272f67cc4348389294145a20eb
-
- 12 Dec, 2022 2 commits
-
-
Olga Gerasimova authored
Summary: X-link: https://github.com/fairinternal/detectron2/pull/589 X-link: https://github.com/facebookresearch/detectron2/pull/4702 Pull Request resolved: https://github.com/facebookresearch/d2go/pull/443 Add MinIoURandomCrop augmentation, compare model performance. Example of aug {F822053068}{F822053066}{F822053051} Data overhead is around 0.04 sec without aug {F822053812} with aug {F822053818} Reviewed By: zechenghe Differential Revision: D41804643 fbshipit-source-id: 8f13f98fa8132378a803534b59e892fbc1b3058c
-
Anastasia Tkach authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/442 Reviewed By: tglik Differential Revision: D41714933 fbshipit-source-id: 5b2b3610af554f6082a4025af0673b4bc34b17ca
-
- 09 Dec, 2022 1 commit
-
-
Mircea Cimpoi authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/436 Renaming `model_ema.py` to `ema.py` (as `modeling` is already in the folder name. Fixing dependencies after rename Reviewed By: wat3rBro Differential Revision: D41685115 fbshipit-source-id: 006999a020a901ea8be4b71e072d688bd36cdce2
-
- 08 Dec, 2022 1 commit
-
-
Siddharth Shah authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/439 As title Reviewed By: mattcyu1 Differential Revision: D41759804 fbshipit-source-id: 929efa960be570f0fe8543600e012d1bf037ab3b
-
- 30 Nov, 2022 6 commits
-
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/432 We support caching of tuples since they behave similarly to lists Reviewed By: XiaoliangDai Differential Revision: D41483876 fbshipit-source-id: 9d741074f8e2335ddd737ae3f1bdb288910f5564
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/431 Add a generic domain adaptation algorithm. This algorithm: * gets domain0 data out of the dataloader * runs domain0 data into the model and saves target layer output * gets domain1 data of the dataloader * runs domain1 data into the model and saves target layer output * runs domain adaptation loss on domain0, domain1 outputs * combines losses using model training iteration This diffs adds `get_preprocess_domain0_input` and `get_preprocess_domain1_input` to the distillation helper. These are functions that the user can use to convert the dataloader output to something that will be used by the model (e.g., pull the domain0 or domain1 key out of a dataloader that returns a dict). Differential Revision: D40970724 fbshipit-source-id: fff050fbe864654fa6cb0df927f6843855ec1c14
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/430 We add losses in distillation by instantiating them in the distillation algorithm's init and then running them during the forward pass. However this has some issues: * the losses are not registered as a module in the model since they we organize them as a list of layerlossmetadata => this means that things like AMP do not behave as expected * the losses are not on the same device as the rest of the model since they are created potentially after the model is moved to a new device This diff solves both of these issues by including a helper function that registers and moves the losses to the same device as the model. `register_layer_losses_and_to_device` takes as input `List[LayerLossMetadata]`, moves the losses to the same device as the model and then registers these losses to the model. Differential Revision: D41296932 fbshipit-source-id: ae7ae0847bce1b5cc481d838b9cae69cea424f25
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/429 Add a teacher type called `no_teacher` which can be specified by the user in the case they ignore the teacher (e.g., domain adaptation). Building the teacher just returns a noop (`nn.Identity`) Differential Revision: D40971788 fbshipit-source-id: fc49ac44224c92806a7be253eefb8454305814eb
-
Peizhao Zhang authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/428 add an augmentation to pad image to square. * For example, image with shape (10, 7, 3) will become (10, 10, 3) and pad with value specified by `pad_value`. Reviewed By: tax313, wat3rBro Differential Revision: D41545182 fbshipit-source-id: 6d5fd9d16984a9904d44f22386920cdf130edda7
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/433 Distillation uses a module called `CachedLayer` to record the outputs of a layer to an internal dict. This dict is typically initialized by the object itself and any value is overwritten every time the model runs. However, sometimes we need more than one output run of the layer (e.g., domain adaptation => we run the model on real, then synthetic data and need to use both outputs). This diff adds a helper to set externally set the cache dict of a model. In other words, we can run `set_cache_dict` on some model to change the dict used by all `CachedLayer` in the model. This allows us to run the model and record some outputs, then change the cache dict and rerun the model to save different outputs. Differential Revision: D40970577 fbshipit-source-id: 49cb851af49ae193d0c8ac9218e02fdaf4e6587b
-
- 28 Nov, 2022 1 commit
-
-
Yanghan Wang authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/427 Re-try previous reverted diff D41350485 (https://github.com/facebookresearch/d2go/commit/0ea6bc1b61ab736ccf1840c58c2b19ed2e9a1282). The problem was essentially because `DefaultTask` is not a subclass of `Runner`, so when we call `Runner`'s class methods from `DefaultTask`, it won't work if the `Runner`'s method also calls other methods that are in `Runner` but not `DefaultTask`. The solution is simply split the data related APIs out into a separate class (mixin), and let `DefaultTask` and `Runner` both subclass from it. Reviewed By: tglik Differential Revision: D41507448 fbshipit-source-id: 8b26c129811436c0bd35e1c6b0705e7035d7e823
-
- 23 Nov, 2022 2 commits
-
-
generatedunixname89002005232357 authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/426 This diff is reverting D41350485 (https://github.com/facebookresearch/d2go/commit/0ea6bc1b61ab736ccf1840c58c2b19ed2e9a1282) D41350485 (https://github.com/facebookresearch/d2go/commit/0ea6bc1b61ab736ccf1840c58c2b19ed2e9a1282) has been identified to be causing the following test or build failures: Tests affected: - https://www.internalfb.com/intern/test/281475052494930/ - https://www.internalfb.com/intern/test/844425005925528/ - https://www.internalfb.com/intern/test/562950029222822/ Here's the Multisect link: https://www.internalfb.com/intern/testinfra/multisect/1429252 Here are the tasks that are relevant to this breakage: T120995919: 4 tests started failing for oncall d2go in the last 2 weeks We're generating a revert to back out the changes in this diff, please note the backout may land if someone accepts it. Reviewed By: wat3rBro Differential Revision: D41470376 fbshipit-source-id: 7d2074e150e6b36a3c260317f859c7f2131295db
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/422 Add a logger to distillation so we can check when distillation is applied Reviewed By: XiaoliangDai Differential Revision: D40375046 fbshipit-source-id: bb1d821fa26fb2da75e82122a30307fcccf7e558
-
- 22 Nov, 2022 1 commit
-
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/421 Add some reasonable defaults when running knowledge distillation * get_default_kd_image_classification_layer_losses => returns cross entropy loss on the output of the student classification layer and the teacher output (this is what the imagenet distillation uses) * DefaultLossCombiner => simple function to multiply the losses by some weights Unsure if these should go in `distillation.py` or a separate place (e.g., defaults or classification) Reviewed By: chihyaoma Differential Revision: D40330718 fbshipit-source-id: 5887566d88e3a96d01aca133c51041126b2692cc
-
- 21 Nov, 2022 1 commit
-
-
Yanghan Wang authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/423 The `DefaultTask` has forked the implementation of some runner methods from `Detectron2GoRunner`, which is not necessary since there should be no differences. This might cause issue that we update the one from `Detectron2GoRunner` but forgot about `DefaultTask`. Reviewed By: chihyaoma Differential Revision: D41350485 fbshipit-source-id: 38a1764a7cc77dc13939ac7d59f35584bf9dab9b
-
- 19 Nov, 2022 1 commit
-
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/420 Adds knowledge distillation as a generic algorithm that can be used by various projects. If eval, the algorithm just returns the result of the student model. If training, the algorithm feeds the input into both the student and teacher model. The user provides a list of `LayerLossMetadata` that provides the layers and losses run on these layers. The algorithm uses dynamic mixin to record the outputs of the relevant layers and compute the losses after both models are run. We provide student and teacher preprocessing as a placeholder before we support a more generic dataloader which can provide different inputs to the student and teacher (e.g., as of now, if you want to provide the teacher with a larger input then the dataloader should return a large input and the student preprocessing can downsample the input). We add the following functions as part of the user customizable distillation helper: * get_teacher => return a teacher that can be used directly by the KD algorithm * get_layer_losses => return a list of `LayerLossMetadata` that provides the layers and losses * get_preprocess_student_input => manipulate the output of the dataloader before passing to the student * get_preprocess_teacher_input => manipulate the output of the dataloader before passing to the teacher * get_combine_losses => since we may want to weight the student and distillation losses, return a function that can manipulate the loss_dict Reviewed By: chihyaoma Differential Revision: D40326412 fbshipit-source-id: 2fb0e818a7d5b120d62fb7aba314ff96cc7e10c5
-
- 18 Nov, 2022 1 commit
-
-
Tao Xu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/424 The diffusion model need to customized eps for the AdamW optimizer. For example the prior of Dalle2 trained with adam_eps=1.0e-06 while its decoder trained with adam_eps=1.0e-08 Add the config for AdamW's eps to d2go pipeline with its default vaule same as the official doc: https://pytorch.org/docs/stable/generated/torch.optim.AdamW.html Reviewed By: newstzpz Differential Revision: D41363142 fbshipit-source-id: 72f9a4084e229312807aad28b7aba8fec9116013
-
- 17 Nov, 2022 3 commits
-
-
Anthony Chen authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/396 Integrate PyTorch FSDP, which supports two sharding modes: 1. gradient + optimizer sharding; 2. full model sharding (params + gradient + optimizer). This feature is enabled in the train_net.py code path. Sources * Integration follows this tutorial: https://pytorch.org/tutorials/intermediate/FSDP_tutorial.html API changes * Add new config keys to support the new feature. Refer to mobile-vision/d2go/d2go/trainer/fsdp.py for the full list of config options * Add `FSDPCheckpointer` as an inheritance of `QATCheckpointer` to support special loading/saving logic for FSDP models Reviewed By: wat3rBro Differential Revision: D39228316 fbshipit-source-id: 342ecb3bcbce748453c3fba2d6e1b7b7e478473c
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/419 This diff adds a metadata class `LayerLossMetadata` to help keep track of the losses we want to compute over layers. The class contains the type of loss, loss name, and layer names. This diff adds a helper function to iterate over a list of `LayerLossMetadata` and return a dict containing the results. Reviewed By: chihyaoma Differential Revision: D40286564 fbshipit-source-id: b269dc63cc90a437ca279379d759c3106016327c
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/418 This diff adds a function that can be used to add `CachedLayers` to a model. Function iterates over named modules and dynamically mixes in `CachedLayer` to target modules. This diff adds a function to remove the cached layers. Reviewed By: Minione Differential Revision: D40285806 fbshipit-source-id: 3137d19927d8fb9ec924a77c9085aea29fe94d5e
-
- 16 Nov, 2022 2 commits
-
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/417 This diff adds a layer `CachedLayer` which is meant to be used with dynamic mixin. This layer runs the original module and clones the output into a dictionary provided by the user. The main use case is in distillation where we dynamically mixin these layers to the layers that the user wants to compute various losses. See subsequent diffs to get integration with distillation. Reviewed By: Minione Differential Revision: D40285573 fbshipit-source-id: 2058deff8b96f63aebd1e9b9933a5352b5197111
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/416 Distillation assumes teacher model has an attribute "device". Sometimes this attribute is actually a property (e.g., generalizedrcnn) but there is zero guarantee that it exists. We add a helper function to move the model to the device and add this attribute if needed. Reviewed By: chihyaoma Differential Revision: D40283954 fbshipit-source-id: 42921653eac8a79499e22edac29aa6aeac016e8a
-
- 15 Nov, 2022 1 commit
-
-
Matthew Yu authored
Summary: Pull Request resolved: https://github.com/facebookresearch/d2go/pull/415 The user can build a teacher by providing a trained config. However this model may have been trained using gpu whereas the user wants to load the model on cpu, this diff supports this use case by allowing the user to specify `cfg.DISTILLATION.TEACHER.DEVICE` as override. Reviewed By: sstsai-adl Differential Revision: D40125236 fbshipit-source-id: f1fd797a155e12b31bb7fcbc5e4997ee8eb23539
-