Unverified Commit c057301e authored by Emily's avatar Emily Committed by GitHub
Browse files

frugally-deep: revert bump&backport CMake 4 compat, rocmPackages.miopen: add...

frugally-deep: revert bump&backport CMake 4 compat, rocmPackages.miopen: add regression test (#444645)
parents e8f62c1f 12004986
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  fetchpatch,
  fetchFromGitHub,
  gitUpdater,
  cmake,
  functionalplus,
  eigen,
  nlohmann_json,
  doctest,
  python3Packages,
  buildTests ? false, # Needs tensorflow
  # for tests
  doctest,
  rocmPackages,
}:

stdenv.mkDerivation (finalAttrs: {
  pname = "frugally-deep";
  version = "0.18.2-unstable-2025-06-16";
  # be careful bumping this, frugally-deep may change its model metadata format
  # in ways that only fail at runtime. MIOpen is currently the only package
  # relying on this, run passthru.tests.miopen-can-load-models to check
  version = "0.15.24-p0";

  src = fetchFromGitHub {
    owner = "Dobiasd";
    repo = "frugally-deep";
    rev = "30a4ce4c932ca810a5a77c4ab943a520bb1048fe";
    hash = "sha256-tcwCRSHhN61ZFDFVQ/GItvgSSjeLSbFDoNMqwswtvto=";
    rev = "v${finalAttrs.version}";
    hash = "sha256-yg2SMsYOOSOgsdwIH1bU3iPM45z6c7WeIrgOddt3um4=";
  };

  patches = [
    (fetchpatch {
      # Backport CMake 4 compat so we can stay on 0.15 for now
      name = "update-minimum-cmake4-huntergate.patch";
      url = "https://github.com/Dobiasd/frugally-deep/commit/30a4ce4c932ca810a5a77c4ab943a520bb1048fe.patch";
      hash = "sha256-J5z+jQis8N2mzWu2Qm7J0fPkrplpjgDCOAJT7binz04=";
    })
  ];

  nativeBuildInputs = [
    cmake
  ]
@@ -43,6 +58,11 @@ stdenv.mkDerivation (finalAttrs: {
  ];

  cmakeFlags = lib.optionals buildTests [ "-DFDEEP_BUILD_UNITTEST=ON" ];
  passthru.tests.miopen-can-load-models =
    rocmPackages.miopen.passthru.tests.can-load-models.override
      {
        frugally-deep = finalAttrs.finalPackage;
      };
  passthru.updateScript = gitUpdater;

  meta = with lib; {
+12 −0
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  callPackage,
  fetchFromGitHub,
  fetchpatch,
  rocmUpdateScript,
@@ -297,6 +298,17 @@ stdenv.mkDerivation (finalAttrs: {

  requiredSystemFeatures = [ "big-parallel" ];

  passthru.tests = {
    # Ensure all .tn.model files can be loaded by whatever version of frugally-deep we have
    # This is otherwise hard to verify as MIOpen will only use these models on specific,
    # expensive Instinct GPUs
    # If MIOpen stops embedding .tn.model files the test will also fail, and can be deleted,
    # likely along with the frugally-deep dependency
    can-load-models = callPackage ./test-frugally-deep-model-loading.nix {
      inherit (finalAttrs) src version;
      inherit frugally-deep nlohmann_json;
    };
  };
  passthru.updateScript = rocmUpdateScript {
    name = finalAttrs.pname;
    inherit (finalAttrs.src) owner;
+55 −0
Original line number Diff line number Diff line
#include <fdeep/fdeep.hpp>
#include <iostream>
#include <filesystem>
#include <vector>
#include <string>

int main() {
    std::vector<std::string> model_files;
    std::string src_dir = std::getenv("SRC_DIR") ? std::getenv("SRC_DIR") : ".";

    // collect *tn.model files except _metadata
    try {
        for (const auto& entry : std::filesystem::recursive_directory_iterator(src_dir)) {
            if (entry.is_regular_file()) {
                std::string path = entry.path().string();
                if (path.find("tn.model") != std::string::npos && path.find("_metadata.") == std::string::npos) {
                    model_files.push_back(path);
                }
            }
        }
    } catch (const std::exception& e) {
        std::cerr << "Error scanning directory: " << e.what() << std::endl;
        return 1;
    }

    if (model_files.empty()) {
        std::cout << "No *.tn.model files found in " << src_dir << std::endl;
        return 1;
    }

    std::cout << "Found " << model_files.size() << " model files to test" << std::endl;

    int failed_count = 0;
    for (const auto& model_file : model_files) {
        std::cout << "Loading: " << model_file << " ... ";
        std::cout.flush();

        try {
            const auto model = fdeep::load_model(model_file);
            std::cout << "OK" << std::endl;
        } catch (const std::exception& e) {
            std::cout << "FAILED: " << e.what() << std::endl;
            failed_count++;
        }
    }

    if (failed_count > 0) {
        std::cerr << "\n" << failed_count << " out of " << model_files.size()
                    << " models failed to load" << std::endl;
        return 1;
    }

    std::cout << "\nAll " << model_files.size() << " models loaded successfully!" << std::endl;
    return 0;
}
+49 −0
Original line number Diff line number Diff line
{
  lib,
  stdenv,
  eigen,
  frugally-deep,
  functionalplus,
  nlohmann_json,
  src,
  version,
}:

stdenv.mkDerivation {
  pname = "miopen-frugally-deep-model-test";
  inherit version src;

  dontConfigure = true;
  dontInstall = true;
  doCheck = true;

  buildPhase = ''
    runHook preBuild

    $CXX -std=c++20 \
        -I${lib.getDev eigen}/include/eigen3 \
        -I${lib.getDev functionalplus}/include \
        -I${lib.getDev frugally-deep}/include \
        -I${lib.getDev nlohmann_json}/include \
        ${./test-frugally-deep-model-loading.cpp} \
        -o test_models

    runHook postBuild
  '';

  checkPhase = ''
    runHook preCheck

    echo "Running model loading tests..."
    SRC_DIR="${src}" ./test_models
    mkdir -p $out

    runHook postCheck
  '';

  meta = {
    description = "Test that frugally-deep can load MIOpen model files";
    maintainers = with lib.teams; [ rocm ];
    platforms = lib.platforms.linux;
  };
}