#![cfg_attr(feature = "nightly", feature(generic_const_exprs))] #[cfg(feature = "nightly")] fn main() { use dfdx::prelude::*; use std::time::Instant; type BasicBlock = Residual<( Conv2D, BatchNorm2D, ReLU, Conv2D, BatchNorm2D, )>; type Downsample = GeneralizedResidual< ( Conv2D, BatchNorm2D, ReLU, Conv2D, BatchNorm2D, ), (Conv2D, BatchNorm2D), >; type Head = ( Conv2D<3, 64, 7, 2, 3>, BatchNorm2D<64>, ReLU, MaxPool2D<3, 2, 1>, ); type Resnet18 = ( Head, (BasicBlock<64>, ReLU, BasicBlock<64>, ReLU), (Downsample<64, 128>, ReLU, BasicBlock<128>, ReLU), (Downsample<128, 256>, ReLU, BasicBlock<256>, ReLU), (Downsample<256, 512>, ReLU, BasicBlock<512>, ReLU), (AvgPoolGlobal, Linear<512, NUM_CLASSES>), ); let dev = AutoDevice::default(); let m = dev.build_module::, f32>(); let x: Tensor, f32, _> = dev.sample_normal(); const PROBES: u32 = 10; let start = Instant::now(); for _ in 0..PROBES { let _y = m.forward(x.clone()); } println!("Average unbatched forward: {:?}", start.elapsed() / PROBES); let x: Tensor, f32, _> = dev.sample_normal(); let start = Instant::now(); for _ in 0..PROBES { let _y = m.forward(x.clone()); } println!( "Average batched (16) forward: {:?}", start.elapsed() / PROBES ); } #[cfg(not(feature = "nightly"))] fn main() { panic!("Run with `cargo +nightly run ...` to run this example."); }