1#![warn(clippy::all)]
37#![allow(clippy::cast_possible_truncation)]
38#![allow(clippy::cast_sign_loss)]
39#![allow(clippy::cast_precision_loss)]
40#![allow(clippy::cast_possible_wrap)]
41#![allow(clippy::missing_errors_doc)]
42#![allow(clippy::missing_panics_doc)]
43#![allow(clippy::must_use_candidate)]
44#![allow(clippy::module_name_repetitions)]
45#![allow(clippy::similar_names)]
46#![allow(clippy::doc_markdown)]
47#![allow(clippy::uninlined_format_args)]
48
49#[cfg(feature = "core")]
54pub use axonml_core as core;
55
56#[cfg(feature = "core")]
57pub use axonml_tensor as tensor;
58
59#[cfg(feature = "core")]
60pub use axonml_autograd as autograd;
61
62#[cfg(feature = "nn")]
67pub use axonml_nn as nn;
68
69#[cfg(feature = "nn")]
70pub use axonml_optim as optim;
71
72#[cfg(feature = "data")]
77pub use axonml_data as data;
78
79#[cfg(feature = "vision")]
84pub use axonml_vision as vision;
85
86#[cfg(feature = "text")]
87pub use axonml_text as text;
88
89#[cfg(feature = "audio")]
90pub use axonml_audio as audio;
91
92#[cfg(feature = "distributed")]
93pub use axonml_distributed as distributed;
94
95#[cfg(feature = "profile")]
96pub use axonml_profile as profile;
97
98#[cfg(feature = "llm")]
99pub use axonml_llm as llm;
100
101#[cfg(feature = "jit")]
102pub use axonml_jit as jit;
103
104#[cfg(feature = "onnx")]
105pub use axonml_onnx as onnx;
106
107#[cfg(feature = "serialize")]
108pub use axonml_serialize as serialize;
109
110#[cfg(feature = "quant")]
111pub use axonml_quant as quant;
112
113#[cfg(feature = "fusion")]
114pub use axonml_fusion as fusion;
115
116#[cfg(feature = "hvac")]
117pub use axonml_hvac as hvac;
118
119#[cfg(feature = "train")]
120pub use axonml_train as train;
121
122pub mod monitor;
128pub use monitor::TrainingMonitor;
129
130pub mod prelude {
140 #[cfg(feature = "core")]
142 pub use axonml_core::{DType, Device, Error, Result};
143
144 #[cfg(feature = "core")]
146 pub use axonml_tensor::Tensor;
147
148 #[cfg(feature = "core")]
150 pub use axonml_autograd::{Variable, no_grad};
151
152 #[cfg(feature = "nn")]
154 pub use axonml_nn::{
155 AvgPool2d, BCELoss, BatchNorm1d, BatchNorm2d, Conv2d, CrossEntropyLoss, Dropout, Embedding,
156 GELU, GRU, L1Loss, LSTM, LayerNorm, LeakyReLU, Linear, MSELoss, MaxPool2d, Module,
157 MultiHeadAttention, Parameter, RNN, ReLU, Sequential, SiLU, Sigmoid, Softmax, Tanh,
158 };
159
160 #[cfg(feature = "nn")]
162 pub use axonml_optim::{
163 Adam, AdamW, CosineAnnealingLR, ExponentialLR, LRScheduler, Optimizer, RMSprop, SGD, StepLR,
164 };
165
166 #[cfg(feature = "data")]
168 pub use axonml_data::{DataLoader, Dataset, RandomSampler, SequentialSampler, Transform};
169
170 #[cfg(feature = "vision")]
172 pub use axonml_vision::{
173 CenterCrop, ImageNormalize, LeNet, RandomHorizontalFlip, Resize, SimpleCNN, SyntheticCIFAR,
174 SyntheticMNIST,
175 };
176
177 #[cfg(feature = "text")]
179 pub use axonml_text::{
180 BasicBPETokenizer, CharTokenizer, LanguageModelDataset, SyntheticSentimentDataset,
181 TextDataset, Tokenizer, Vocab, WhitespaceTokenizer,
182 };
183
184 #[cfg(feature = "audio")]
186 pub use axonml_audio::{
187 AddNoise, MFCC, MelSpectrogram, NormalizeAudio, Resample, SyntheticCommandDataset,
188 SyntheticMusicDataset,
189 };
190
191 #[cfg(feature = "distributed")]
193 pub use axonml_distributed::{
194 DDP, DistributedDataParallel, ProcessGroup, World, all_reduce_mean, all_reduce_sum,
195 barrier, broadcast,
196 };
197
198 #[cfg(feature = "profile")]
200 pub use axonml_profile::{
201 Bottleneck, BottleneckAnalyzer, ComputeProfiler, MemoryProfiler, ProfileGuard,
202 ProfileReport, Profiler, TimelineProfiler,
203 };
204
205 #[cfg(feature = "llm")]
207 pub use axonml_llm::{
208 Bert, BertConfig, BertForMaskedLM, BertForSequenceClassification, GPT2, GPT2Config,
209 GPT2LMHead, GenerationConfig, TextGenerator,
210 };
211
212 #[cfg(feature = "train")]
214 pub use axonml_train::{
215 AdversarialTrainer, Callback, EarlyStopping, ProgressLogger, TrainingConfig,
216 TrainingHistory, TrainingMetrics,
217 };
218
219 #[cfg(feature = "jit")]
221 pub use axonml_jit::{
222 CompiledFunction, Graph, JitCompiler, Optimizer as JitOptimizer, TracedValue, trace,
223 };
224}
225
226#[must_use]
232pub fn version() -> &'static str {
233 env!("CARGO_PKG_VERSION")
234}
235
236#[must_use]
238pub fn features() -> String {
239 let mut features = Vec::new();
240
241 #[cfg(feature = "core")]
242 features.push("core");
243
244 #[cfg(feature = "nn")]
245 features.push("nn");
246
247 #[cfg(feature = "data")]
248 features.push("data");
249
250 #[cfg(feature = "vision")]
251 features.push("vision");
252
253 #[cfg(feature = "text")]
254 features.push("text");
255
256 #[cfg(feature = "audio")]
257 features.push("audio");
258
259 #[cfg(feature = "distributed")]
260 features.push("distributed");
261
262 #[cfg(feature = "profile")]
263 features.push("profile");
264
265 #[cfg(feature = "llm")]
266 features.push("llm");
267
268 #[cfg(feature = "jit")]
269 features.push("jit");
270
271 #[cfg(feature = "onnx")]
272 features.push("onnx");
273
274 #[cfg(feature = "serialize")]
275 features.push("serialize");
276
277 #[cfg(feature = "quant")]
278 features.push("quant");
279
280 #[cfg(feature = "fusion")]
281 features.push("fusion");
282
283 #[cfg(feature = "hvac")]
284 features.push("hvac");
285
286 #[cfg(feature = "train")]
287 features.push("train");
288
289 if features.is_empty() {
290 "none".to_string()
291 } else {
292 features.join(", ")
293 }
294}
295
296#[cfg(test)]
301mod tests {
302 use super::*;
303
304 #[test]
305 fn test_version() {
306 let v = version();
307 assert!(!v.is_empty());
308 }
309
310 #[test]
311 fn test_features() {
312 let f = features();
313 assert!(f.contains("core"));
314 }
315
316 #[cfg(feature = "core")]
317 #[test]
318 fn test_tensor_creation() {
319 use tensor::Tensor;
320 let t = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]).unwrap();
321 assert_eq!(t.shape(), &[2, 2]);
322 }
323
324 #[cfg(feature = "core")]
325 #[test]
326 fn test_variable_creation() {
327 use autograd::Variable;
328 use tensor::Tensor;
329 let t = Tensor::from_vec(vec![1.0, 2.0, 3.0], &[3]).unwrap();
330 let v = Variable::new(t, true);
331 assert_eq!(v.data().shape(), &[3]);
332 }
333
334 #[cfg(feature = "nn")]
335 #[test]
336 fn test_linear_layer() {
337 use autograd::Variable;
338 use nn::Linear;
339 use nn::Module;
340 use tensor::Tensor;
341
342 let layer = Linear::new(4, 2);
343 let input = Variable::new(Tensor::from_vec(vec![1.0; 4], &[1, 4]).unwrap(), false);
344 let output = layer.forward(&input);
345 assert_eq!(output.data().shape(), &[1, 2]);
346 }
347}