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
This commit is contained in:
AI-anonymous
2026-05-19 16:05:15 +02:00
commit 9bbe253810
32 changed files with 2182 additions and 0 deletions

40
src/spectral.cpp Normal file
View File

@@ -0,0 +1,40 @@
#include "fces/spectral.hpp"
#include <numeric>
namespace fces {
SpectralSensor::SpectralSensor(torch::nn::Module& /*model*/) {}
void SpectralSensor::track_layer(const std::string& name, const torch::Tensor& weight) {
if (weight.dim() >= 2) {
layer_ranks_[name] = compute_effective_rank(weight);
}
}
float SpectralSensor::get_global_rank() const {
if (layer_ranks_.empty()) return 0.0f;
float sum = 0.0f;
for (const auto& [_, rank] : layer_ranks_) {
sum += rank;
}
return sum / static_cast<float>(layer_ranks_.size());
}
void SpectralSensor::reset() {
layer_ranks_.clear();
}
float SpectralSensor::compute_effective_rank(const torch::Tensor& weight) {
// SVD-based effective rank (Shannon entropy of normalized singular values)
auto svd = torch::linalg::svdvals(weight.to(torch::kFloat32));
auto s = svd / svd.sum();
auto log_s = torch::log(s + 1e-10f);
float entropy = -(s * log_s).sum().item<float>();
return std::exp(entropy);
}
float SpectralController::compute_alpha(float global_rank, float grokking_coefficient) const {
return global_rank * grokking_coefficient;
}
} // namespace fces