Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify AutoAugment graph #4751

Merged
merged 3 commits into from
Apr 4, 2023
Merged

Conversation

stiepan
Copy link
Member

@stiepan stiepan commented Mar 28, 2023

Category:

Refactoring (Redesign of existing code that doesn't affect functionality

Description:

This PR combines a couple of improvements to AutoAugment processing graph.

  1. The list of augmentations to split processing into is created independently for each stage - this can reduces the size of split-merge tree generated by the select operation.

For example, the default v0 policy uses 25 sub-policies, each sub-policy is a sequence of (at most) 2 augmentations. Even though there are 25 sub-policies, there are only 11 unique augmentations present in those sub-polcies. DALI already splits the computation only in 11 parts. However, it can be further improved if the operators used in given stages of sub-policies form even smaller groups. In case of the default v0 policy, it is 8 vs 11.

In other words, when the comutation is split to apply the "i-th" augmentation in a sequence according to selected sub-polciy, there is no need to take into account all augmentations present in all sub-polcies, but only the augmentations at the i-th position in all sub-policies.

  1. The signed_bin helper that handles random negation of magnitudes can now accept additional shape parameter. With that, if you have a multiple random augmentations to apply in a sequence, you can generate the random signs of magnitudes once for all stages, rather than do it for every stage separately.

Additional information:

Affected modules and functionalities:

AutoAugment (points 1., 2.), RandAugment (point 2.).

Key points relevant for the review:

Tests:

  • Existing tests apply
  • New tests added
    • Python tests
    • GTests
    • Benchmark
    • Other
  • N/A

Checklist

Documentation

  • Existing documentation applies
  • Documentation updated
    • Docstring
    • Doxygen
    • RST
    • Jupyter
    • Other
  • N/A

DALI team only

Requirements

  • Implements new requirements
  • Affects existing requirements
  • N/A

REQ IDs: N/A

JIRA TASK: DALI-3357

stiepan added 3 commits March 28, 2023 17:06
Signed-off-by: Kamil Tokarski <[email protected]>
self._random_sign = random_sign
self._signed_magnitude_idx = signed_magnitude_idx

def __getitem__(self, idx: int):
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This enables the signed_bin(mutli_stage_bin)[stage_idx].

@stiepan stiepan added the automatic augmentations Automatic augmentations (AutoAugment, RandAugment, TrivialAugment and more) support in DALI. label Mar 29, 2023
@stiepan
Copy link
Member Author

stiepan commented Mar 30, 2023

!build

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [7762008]: BUILD STARTED

@dali-automaton
Copy link
Collaborator

CI MESSAGE: [7762008]: BUILD PASSED

@szalpal szalpal assigned klecki and unassigned szalpal Mar 31, 2023
Comment on lines +227 to +229
The output is a tuple of matrix `m` and per stage operators augmentations list `augments`,
such that for policy `sub_policy_idx` as the `stage_idx`-ith operation in a sequence, the
`augments[stage_idx][m[sub_policy_idx][stage_idx]]` operator should be called.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I may try to expand the comment:

Suggested change
The output is a tuple of matrix `m` and per stage operators augmentations list `augments`,
such that for policy `sub_policy_idx` as the `stage_idx`-ith operation in a sequence, the
`augments[stage_idx][m[sub_policy_idx][stage_idx]]` operator should be called.
The output is a tuple `(m, augments)`, where `augments` is a list of augmentations to be
used for given stage - each entry contains the reduced list of unique augmentations to be
used for that stage.
The `m` matrix contains the mapping from the original sub_policy_id, to the index within the
reduced list, for every stage.T
That is for policy `sub_policy_idx` as the `stage_idx`-ith operation in a sequence, the
`augments[stage_idx][m[sub_policy_idx][stage_idx]]` operator should be called.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll merge this one, revase the #4753 and expand the comment there.

Comment on lines 117 to 123
for stage_id in range(max_policy_len):
magnitude_bin = magnitude_bins[stage_id]
if use_signed_magnitudes:
magnitude_bin = signed_bin(magnitude_bin)
if should_run[stage_id] < run_probabilities[stage_id]:
op_kwargs = dict(sample=sample, magnitude_bin=magnitude_bin,
op_kwargs = dict(sample=sample, magnitude_bin=magnitude_bins[stage_id],
num_magnitude_bins=policy.num_magnitude_bins, **kwargs)
sample = _pretty_select(augmentations, aug_ids[stage_id], op_kwargs,
sample = _pretty_select(augmentations[stage_id], aug_ids[stage_id], op_kwargs,
auto_aug_name='apply_auto_augment',
ref_suite_name='get_image_net_policy')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Honestly, this is so cool ;)

@stiepan stiepan merged commit c0fc10d into NVIDIA:main Apr 4, 2023
@stiepan stiepan mentioned this pull request Apr 4, 2023
18 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automatic augmentations Automatic augmentations (AutoAugment, RandAugment, TrivialAugment and more) support in DALI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants