1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
//! The derive crate of Burn.
extern crate derive_new;
use TokenStream;
pub
pub
pub
pub
/// Derive macro for the `Module` trait.
///
/// # Sub-modules
///
/// By default, the macro automatically detects sub-modules and parameters as module types.
///
/// Any field not recognized as a module type is assumed to be a non-module
/// and is skipped by the module system (not persistent, not visited).
///
/// ## Generics
///
/// Generic type parameters (e.g., `field: M`) are assumed to be sub-modules by default.
/// If a generic field represents some other runtime state or configuration, you can use
/// the `#[module(skip)]` attribute to provide a hint.
///
/// # Field Attributes
///
/// ## `#[module(skip)]`
///
/// Explicitly marks a field to be ignored by the module derive.
///
/// Skipped fields are not parameters, not modules, and are not persistent.
/// This is equivalent to the deprecated `Ignored<T>` wrapper.
///
/// ### Requirements
///
/// The field must implement: `Debug + Clone + Send`.
///
/// # Example
///
/// ```ignore
/// #[derive(Module, Debug)]
/// pub struct MyModule<B: Backend, M, N: NonModuleTrait> {
/// /// A normal parameter.
/// weights: Param<Tensor<B, 2>>,
/// /// A field configured at runtime.
/// dropout_prob: f64,
/// /// A field that is recomputed at runtime.
/// cached_mask: Option<Tensor<B, 2>>,
/// /// A field that contains some debug state.
/// debug_state: String,
/// /// Treated as a module (default for generics).
/// inner: M,
/// /// Hint required: this generic is NOT a module.
/// #[module(skip)]
/// other: N,
/// }
/// ```
/// Derive macro for the record.
/// Derive macro for the config.