Skip to content
This repository was archived by the owner on Apr 28, 2023. It is now read-only.

Genetic Tuning Improvements #160

Closed
wants to merge 9 commits into from
Closed

Genetic Tuning Improvements #160

wants to merge 9 commits into from

Conversation

thetheodor
Copy link

@thetheodor thetheodor commented Mar 15, 2018

Use better candidate sampling and make the selection phase more explicit and tunable by command line flags.

@prigoyal
Copy link
Contributor

@ttheodor can you provide some information on this? I am curious to know how sampling is changing and the effect on performance. thanks!

Copy link
Contributor

@prigoyal prigoyal left a comment

Choose a reason for hiding this comment

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

nits for code reusability

@@ -72,9 +74,35 @@ void mutate(
}
}

void normalizeVector(std::vector<double>& v) {
double mean(std::vector<double>& v) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can these be moved to the utils file https://github.com/facebookresearch/TensorComprehensions/blob/master/src/autotuner/utils/utils.cc

where we already have mathematical functions implemented?

return sum / v.size();
}

double stdv(std::vector<double>& v, double mean) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can these be moved to the utils file https://github.com/facebookresearch/TensorComprehensions/blob/master/src/autotuner/utils/utils.cc

where we already have mathematical functions implemented?

return std::sqrt(squareSum / v.size());
}

void sigmaScale(std::vector<double>& v) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can these be moved to the utils file https://github.com/facebookresearch/TensorComprehensions/blob/master/src/autotuner/utils/utils.cc

where we already have mathematical functions implemented?

@thetheodor
Copy link
Author

@prigoyal the first commit message includes a motivation. I'll add descriptions to the others.

@@ -113,6 +115,7 @@ class GeneticSearch {
Population population;
TuningConfiguration lastBestConf;
const size_t kMaxPopulationSize;
const size_t kMatingPoolSize;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this being exposed as an option to set? like we specify pop_size etc. via flags

Copy link
Author

Choose a reason for hiding this comment

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

Right now it is not. I'll expose it in a subsequent commit.

Copy link
Contributor

Choose a reason for hiding this comment

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

awesome :)

Copy link
Contributor

@prigoyal prigoyal left a comment

Choose a reason for hiding this comment

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

nits

@@ -164,6 +193,7 @@ GeneticSearch::GeneticSearch(
: population(),
lastBestConf(confs[0]),
kMaxPopulationSize(n),
kMatingPoolSize(n * 3),
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious: what is the reason for number 3? can we move the number to header file as a static constexpr int? :)

Copy link
Author

Choose a reason for hiding this comment

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

Right now it is semi-arbitrary: it is the maximum number of candidates that can be used during breeding.

I'll expose it as an option in a subsequent commit.

@prigoyal
Copy link
Contributor

thanks @ttheodor , can you update PR summary with slight context :)

@ftynse
Copy link
Contributor

ftynse commented Mar 15, 2018

@ttheodor I have a hack for you: if you first push only one commit to a branch and create a PR, github will pick up the description from that commit. Once PR is created, pushing more commits does not change the description

Copy link
Contributor

@nicolasvasilache nicolasvasilache left a comment

Choose a reason for hiding this comment

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

Looks good.
Needs a tuning run though, I will not get to it before coming back from travel.

@thetheodor thetheodor changed the title [genetic search] Better candidate sampling Genetic Tuning Improvements Mar 16, 2018
@thetheodor thetheodor force-pushed the genetic_improv branch 2 times, most recently from ba40df5 to d90a51c Compare March 20, 2018 12:26
@thetheodor thetheodor changed the base branch from dev to master March 20, 2018 12:26
@prigoyal
Copy link
Contributor

@caffe2bot retest this please

@thetheodor thetheodor force-pushed the genetic_improv branch 2 times, most recently from de8f30f to 58fb6c4 Compare April 4, 2018 14:17
@thetheodor thetheodor force-pushed the genetic_improv branch 2 times, most recently from a109131 to 99ec2b3 Compare April 5, 2018 16:03
@ezyang
Copy link

ezyang commented Apr 5, 2018

@caffe2bot retest this please

1 similar comment
@ezyang
Copy link

ezyang commented Apr 5, 2018

@caffe2bot retest this please

@thetheodor thetheodor force-pushed the genetic_improv branch 4 times, most recently from 8f7bc63 to eb3c330 Compare April 12, 2018 13:19
Theodoros Theodoridis added 3 commits April 13, 2018 17:23
Using an unscaled fitness value for selection is problematic:

-Outstanding individuals take over very quickly, this leads to
premature convergence.

-When fitness values are close together, very litle selection
pressure is applied and selection is almost uniformly random.
Having slightly better fitness does not improve an individual's
survival chances.

-Transposing the fitness function (e.g. adding a constant value)
changes the selection probabilities even though the location of the
optimum (and the "shape" of the fitness) remain unchanged.

Scaling the fitness function helps ameliorate those issues.

Sigma scaling is used:

fitness' = max(fitness - (mean_fitness - 2 * std_fitness), 0)
Stochastic Universal Sampling is an improvement upon the roulette
algorithm that was previously used
Theodoros Theodoridis added 6 commits April 13, 2018 17:23
Previously each generation had mu candidates and generated mu
children which all survided. This meant that really bad candidates
that were randomly generated would survive across generations.

With this change, lambda (typically larger thatn mu) children are
generated and the best mu survive. The previous behaviour is a
special case in which lambda = mu.
Some candidates survive across across generations. Their runtimes
are stored in the options cache. Previously those candidates would
be benchmarked everytime they were encountered. Now the runtimes
are restored from the caches instead.
Candidates that survive across generations need not be benchmarked
again and thus no compilation and gpu jobs have to be created for
them.
Each generation includes two evalution phases (marked with *):
1) Benchmarking of candidates *
2) Breeding
3) Benchmarking of new candidates and selection *

Except for the first generation usually most of the candidates of
step 1) will have been evaluated during step 3) of the previous
generation.

This commit removed the "Jobs(Compiled,GPU) (0,0)/0" that was
printed during step 1) of almost every generation.

In theory it is possible not to have enough valid candidates to
form a new generation. In those cases step 1) will be run and
the progress message will be printed
@thetheodor
Copy link
Author

Replaced by #453

@thetheodor thetheodor closed this May 28, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants