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

Created a minibatch iterator selection function #57

Merged
merged 23 commits into from
Nov 4, 2022
Merged

Created a minibatch iterator selection function #57

merged 23 commits into from
Nov 4, 2022

Conversation

farhadrclass
Copy link
Contributor

as discussed here #52

@farhadrclass farhadrclass mentioned this pull request Oct 14, 2022
Copy link
Member

@paraynaud paraynaud left a comment

Choose a reason for hiding this comment

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

Thanks, and don't forget to add some tests!

src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
farhadrclass and others added 2 commits October 15, 2022 15:48
Co-authored-by: Paul Raynaud <paul.raynaud66@hotmail.fr>
Co-authored-by: Paul Raynaud <paul.raynaud66@hotmail.fr>
@farhadrclass
Copy link
Contributor Author

I will re-factor the code and also add the tests now

Copy link
Member

@paraynaud paraynaud left a comment

Choose a reason for hiding this comment

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

Thanks @farhadrclass, i suggested some minor changes!

src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Show resolved Hide resolved
src/KnetNLPModels.jl Outdated Show resolved Hide resolved
Project.toml Outdated Show resolved Hide resolved
farhadrclass and others added 2 commits October 19, 2022 11:56
Co-authored-by: Paul Raynaud <paul.raynaud66@hotmail.fr>
@farhadrclass
Copy link
Contributor Author

@paraynaud for some reason the doc builder fails
since it needs knetnlpmodels to run the example and we haven't push the PR, it doesn't have the functions we just wrote

we have to option
accept the PR and it should fix this or make a new one and remove the tutorial to that one

docs/src/tutorial.md Outdated Show resolved Hide resolved
Co-authored-by: Paul Raynaud <paul.raynaud66@hotmail.fr>
Copy link
Member

@paraynaud paraynaud left a comment

Choose a reason for hiding this comment

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

I checked the documentation of the new methods.
I made some changes to ease the understanding.
If you agree with the new doc, we will ask Dominique to finally review the PR.

src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
farhadrclass and others added 4 commits October 24, 2022 20:16
Co-authored-by: Paul Raynaud <paul.raynaud66@hotmail.fr>
Co-authored-by: Paul Raynaud <paul.raynaud66@hotmail.fr>
Co-authored-by: Paul Raynaud <paul.raynaud66@hotmail.fr>
Co-authored-by: Paul Raynaud <paul.raynaud66@hotmail.fr>
@paraynaud
Copy link
Member

@dpo, this one should be ready to go.

docs/src/tutorial.md Outdated Show resolved Hide resolved
docs/src/tutorial.md Outdated Show resolved Hide resolved
@@ -99,6 +103,8 @@ function KnetNLPModel(
x0,
layers_g,
nested_array,
1, #inti the batch current i to 1
Copy link
Member

Choose a reason for hiding this comment

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

I don't understand the comment. Index of the first minibatch? Normally, you don't index iterators. You just loop through them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes but this is because Knet doesn't use the iterator correctly

The way knet does it is to ignore the size and do {i \in [1,data_size-batch_size]} which is terrible but that mean i for batch size of 1000 in MNIST is between 1 to 59999 which is weird for me but that is how it was written (I spent 2 days debugging till I find this weird behavior )

check here the knet random code: https://github.com/denizyuret/Knet.jl/blob/e9bec84b826ee7231db4ca8772fae6eb2fd4bcb9/src/train20/data.jl

function rand(d::Data)
i = rand(0:(d.length-d.batchsize))
return iterate(d, i)[1]
end

So basically their iterator is using i and i actually is the index of the data not the mini-batch,
I am open to suggestion how to fix this since I think the problem is Knet's iterator is to some extend weird

Copy link
Member

Choose a reason for hiding this comment

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

Should "inti" be "init" ? Better write "initialize".

src/utils.jl Show resolved Hide resolved
nlp.current_training_minibatch = rand(nlp.training_minibatch_iterator)
function reset_minibatch_train!(nlp::AbstractKnetNLPModel)
nlp.current_training_minibatch = first(nlp.training_minibatch_iterator)
nlp.i_train = 1
Copy link
Member

Choose a reason for hiding this comment

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

Here, we see that the index 1 is not useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we use the index 1 as a flag for when data is visited or new iteration has started

src/utils.jl Show resolved Hide resolved
src/utils.jl Outdated Show resolved Hide resolved
src/utils.jl Show resolved Hide resolved
farhadrclass and others added 5 commits October 28, 2022 14:48
Co-authored-by: Dominique <dominique.orban@gmail.com>
Co-authored-by: Dominique <dominique.orban@gmail.com>
no need for return 1 since our reset_minibatch_.. does reset them
dpo
dpo previously approved these changes Nov 4, 2022
Copy link
Member

@dpo dpo left a comment

Choose a reason for hiding this comment

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

Thanks! Just a few minor comments. You can merge after that.

docs/src/tutorial.md Outdated Show resolved Hide resolved
docs/src/tutorial.md Outdated Show resolved Hide resolved
docs/src/tutorial.md Outdated Show resolved Hide resolved
@@ -99,6 +103,8 @@ function KnetNLPModel(
x0,
layers_g,
nested_array,
1, #inti the batch current i to 1
Copy link
Member

Choose a reason for hiding this comment

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

Should "inti" be "init" ? Better write "initialize".

src/KnetNLPModels.jl Outdated Show resolved Hide resolved
paraynaud and others added 4 commits November 4, 2022 10:12
Co-authored-by: Dominique <dominique.orban@gmail.com>
Co-authored-by: Dominique <dominique.orban@gmail.com>
Co-authored-by: Dominique <dominique.orban@gmail.com>
@paraynaud paraynaud self-requested a review November 4, 2022 14:31
@dpo dpo merged commit 2833c5d into JuliaSmoothOptimizers:main Nov 4, 2022
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.

None yet

3 participants