Files
FCES-native/benchmarks/bench_step.cpp
AI-anonymous 9bbe253810 feat: scaffold FCES-native C++ project with libtorch integration
- CMakeLists.txt with libtorch, GoogleTest, GoogleBenchmark, OpenMP, pybind11
- Header files: config, controller, population, fitness, evolution, spectral, oscillation, telemetry, optimizer
- Source implementations: controller (full micro-MLP forward pass, mutation, crossover), fitness (Welford's algorithm), oscillation (DFT), spectral (SVD rank), optimizer (sign-SGD stub)
- Tests: controller, population, fitness, optimizer (Google Test)
- Benchmarks: evolve throughput, optimizer step (Google Benchmark)
- Examples: simple optimization, PyTorch/libtorch integration
- Python extension: pybind11 bindings with setup.py
- README with architecture diagram and build instructions
2026-05-19 16:05:15 +02:00

26 lines
719 B
C++

#include <benchmark/benchmark.h>
#include <torch/torch.h>
#include "fces/optimizer.hpp"
using namespace fces;
static void BM_OptimizerStep(benchmark::State& state) {
auto model = torch::nn::Linear(state.range(0), state.range(0) / 2);
std::vector<torch::Tensor> params;
for (auto& p : model->parameters()) params.push_back(p);
FCESOptimizer opt(params, FCESConfig{}.set_lr(1e-3f));
auto x = torch::randn({8, state.range(0)});
for (auto _ : state) {
auto y = model->forward(x);
auto loss = y.sum();
loss.backward();
opt.step();
opt.zero_grad();
benchmark::DoNotOptimize(loss);
}
}
BENCHMARK(BM_OptimizerStep)->Arg(64)->Arg(256)->Arg(1024);