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

Write trainables to module #470

Merged
merged 5 commits into from
Oct 28, 2024
Merged

Write trainables to module #470

merged 5 commits into from
Oct 28, 2024

Conversation

michaeldeistler
Copy link
Contributor

@michaeldeistler michaeldeistler commented Oct 24, 2024

This PR introduces a write_trainables() which adds the trainables to the .nodes and .edges such that they can be used for plotting, printing,...

net.make_trainable("radius")
params = net.get_parameters()

net.write_trainables(params)

Closes #356

Copy link
Contributor

@jnsbck jnsbck left a comment

Choose a reason for hiding this comment

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

Cool!, nice that it needs so few lines of code! Good to go once comments have been adressed

@@ -1044,6 +1045,32 @@ def make_trainable(
f"Number of newly added trainable parameters: {num_created_parameters}. Total number of trainable parameters: {self.base.num_trainable_params}"
)

def write_trainables(self, trainable_params: List[Dict[str, jnp.ndarray]]):
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool! This only works for Module tho, i.e. doing net.cell(0).write_trainables() will only write to self.base.nodes if self == self.base. To be able to call this from a View and for these changes to take affect for the module you need to write to self.base.nodes.loc[self._nodes_in_view], instead of self.nodes. See docstring of View. I think it might actually be nice if you could write only the trainables in View.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

doesn't work, see comments

tests/test_make_trainable.py Show resolved Hide resolved
Copy link
Contributor

@jnsbck jnsbck left a comment

Choose a reason for hiding this comment

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

Feel free to merge this.
Regarding the special treatment of edges: since we are getting rid of synapse view down the line, we can treat edges like nodes. I think this would make a lot of things nicer. Currently working on this as part of #453.

@michaeldeistler michaeldeistler merged commit de1e9f2 into main Oct 28, 2024
1 check passed
@michaeldeistler michaeldeistler deleted the updatemodule branch October 28, 2024 16:21
michaeldeistler added a commit that referenced this pull request Nov 13, 2024
* Write trainables to module

* Allow to write the trainables into the module
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.

update Module after training
2 participants