Skip to content

allow backends to suggest minibatch size #1877

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

Merged
merged 7 commits into from
Nov 14, 2023

Conversation

borg323
Copy link
Member

@borg323 borg323 commented Apr 25, 2023

I only added actual suggestions where it was easy (blas, onednn and onnx).

@@ -222,6 +222,13 @@ class SearchWorker {
this->RunTasks(i);
});
}
target_minibatch_size_ = params_.GetMiniBatchSize();
Copy link
Member

Choose a reason for hiding this comment

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

Not sure whether it's better, but maybe make params_.GetMiniBatchSize() an std::option<int>?

Then it would be possible to do target_minibatch_size_ = params_.GetMiniBatchSize().value_or(search_->network_->GetMiniBatchSize()).

Also, why not put target_minibatch_size_ and max_out_of_order_ into search_ rather than SearchWorker?

Copy link
Member Author

Choose a reason for hiding this comment

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

The change to std::optional<int> seems a bit overcomplicated, even more since this way allows us to keep the 32 minibatch-size default for selfplay with no changes.
It seemed cleaner to put target_minibatch_size_ and max_out_of_order_ in SearchWorker since they are only used there.

@@ -107,6 +107,7 @@ class Network {
virtual const NetworkCapabilities& GetCapabilities() const = 0;
virtual std::unique_ptr<NetworkComputation> NewComputation() = 0;
virtual void InitThread(int /*id*/) {}
virtual int GetMiniBatchSize() const { return 256; }
Copy link
Member

Choose a reason for hiding this comment

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

I wonder whether it would be cleaner to add the recommended minibatch size into the NetworkCapabilities rather than adding a new function (not sure which variant I prefer though).

Copy link
Member Author

Choose a reason for hiding this comment

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

The 'NetworkCapabilities' so far only stores properties of the weights file, and I have plans to expand the interface to pass the search minibatch-size value so that the backend can adjust the memory buffer allocations as needed.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe NetworkCapabilities is a poor name, but it still looks cleaner to have all information that backend tells to the calling code in a structure, to make interface less leaky.
It's fine to do refactor this later though.

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm warming up to the idea, but I want to finish with the rest of my plan before doing it. There are some cornet cases I haven't though through yet.

@@ -107,6 +107,7 @@ class Network {
virtual const NetworkCapabilities& GetCapabilities() const = 0;
virtual std::unique_ptr<NetworkComputation> NewComputation() = 0;
virtual void InitThread(int /*id*/) {}
virtual int GetMiniBatchSize() const { return 256; }
Copy link
Member

Choose a reason for hiding this comment

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

Maybe NetworkCapabilities is a poor name, but it still looks cleaner to have all information that backend tells to the calling code in a structure, to make interface less leaky.
It's fine to do refactor this later though.

Copy link
Member

@mooskagh mooskagh left a comment

Choose a reason for hiding this comment

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

It would also make sense to look into proxy backends (i.e. multiplexing etc), whether they have to forward the information from their backends.

UPD: and also it makes me wonder how this new functionality works with the selfplay, as we use multiplexing there and potentially number of simultaneous training games depends on the batch size.

@borg323
Copy link
Member Author

borg323 commented Oct 5, 2023

The proxy backends will be done in a next PR - it needs a similar treatment for threads first.
Selfplay is not (and will not be) affected as the default minibatch-size is not changed to 0 there.

@borg323 borg323 merged commit 8539794 into LeelaChessZero:master Nov 14, 2023
@borg323 borg323 deleted the minibatch branch November 14, 2023 21:06
PikaCat-OuO pushed a commit to official-pikafish/px0 that referenced this pull request Dec 18, 2023
* allow backends to suggest minibatch size
* simple cuda heuristic

(cherry picked from commit 8539794)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants