forked from tracel-ai/burn
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: save and load state (tracel-ai#129)
- Loading branch information
1 parent
3a91c2c
commit 1a1d86d
Showing
6 changed files
with
92 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use super::ParamId; | ||
use crate::module::{Module, ModuleVisitor}; | ||
use burn_tensor::{backend::Backend, Tensor}; | ||
|
||
#[derive(new)] | ||
struct ParamIdCollector<'a> { | ||
param_ids: &'a mut Vec<ParamId>, | ||
} | ||
|
||
impl<'a, B: Backend> ModuleVisitor<B> for ParamIdCollector<'a> { | ||
fn visit<const D: usize>(&mut self, id: &ParamId, _tensor: &Tensor<B, D>) { | ||
self.param_ids.push(id.clone()); | ||
} | ||
} | ||
|
||
/// List all the parameter ids in a module. | ||
pub fn list_param_ids<M: Module>(module: &M) -> Vec<ParamId> { | ||
let mut params_ids = Vec::new(); | ||
let mut visitor = ParamIdCollector::new(&mut params_ids); | ||
module.visit(&mut visitor); | ||
|
||
params_ids | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters