-
Notifications
You must be signed in to change notification settings - Fork 0
Composite Sampler #250
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
Composite Sampler #250
Changes from 1 commit
1d4cbaf
8dfbc8a
3535b0f
e279769
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from __future__ import annotations | ||
|
||
import torch | ||
|
||
from confopt.oneshot.archsampler import BaseSampler | ||
from confopt.oneshot.base import OneShotComponent | ||
|
||
|
||
class CompositeSampler(OneShotComponent): | ||
def __init__( | ||
self, | ||
arch_samplers: list[BaseSampler], | ||
arch_parameters: list[torch.Tensor], | ||
) -> None: | ||
super().__init__() | ||
self.arch_samplers = arch_samplers | ||
self.arch_parameters = arch_parameters | ||
|
||
# get sample frequency from the samplers | ||
self.sample_frequency = arch_samplers[0].sample_frequency | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we still use sampling frequency in the code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, we never change it to epoch in our experiments, but we have option to do that. I'm not sure how handy this can come later, but I think it doesn't hurt to leave it there |
||
for sampler in arch_samplers: | ||
assert ( | ||
self.sample_frequency == sampler.sample_frequency | ||
), "All the sampler must have the same sample frequency" | ||
abhash-er marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
def sample(self, alpha: torch.Tensor) -> torch.Tensor: | ||
sampled_alphas = alpha | ||
for sampler in self.arch_samplers: | ||
sampled_alphas = sampler.sample(sampled_alphas) | ||
|
||
return sampled_alphas | ||
|
||
def new_epoch(self) -> None: | ||
super().new_epoch() | ||
for sampler in self.arch_samplers: | ||
sampler.new_epoch() | ||
|
||
def new_step(self) -> None: | ||
super().new_step() | ||
for sampler in self.arch_samplers: | ||
sampler.new_step() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why inherit from
OneShotComponent
? Why not inherit fromBaseSampler
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was in 2 minds with it as well, but for me, functionality wise- I don't see it as a child of BaseSampler, since it takes a list of BaseSampler within its initialisation which i thought is a special case. So I thought a OneShotComponent is a better option for it. Let me know your opinion about it.