test_qwen_detection.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #include "model_detector.h"
  2. #include <iostream>
  3. #include <vector>
  4. #include <filesystem>
  5. namespace fs = std::filesystem;
  6. // Test function specifically for Qwen model detection
  7. void testQwenDetection(const std::string& modelPath) {
  8. std::cout << "\n=== Testing Qwen Model Detection for: " << modelPath << " ===" << std::endl;
  9. if (!fs::exists(modelPath)) {
  10. std::cout << "ERROR: Model file does not exist!" << std::endl;
  11. return;
  12. }
  13. try {
  14. // Test ModelDetector
  15. ModelDetectionResult result = ModelDetector::detectModel(modelPath);
  16. std::cout << "📋 Detection Results:" << std::endl;
  17. std::cout << " Architecture: " << result.architectureName << std::endl;
  18. std::cout << " Architecture Enum: " << static_cast<int>(result.architecture) << std::endl;
  19. // Check if it's correctly detected as QWEN2VL
  20. bool isCorrectlyDetected = (result.architecture == ModelArchitecture::QWEN2VL);
  21. std::cout << " ✅ Correctly detected as QWEN2VL: " << (isCorrectlyDetected ? "YES" : "NO") << std::endl;
  22. if (!isCorrectlyDetected) {
  23. std::cout << " ❌ FAILED: Expected QWEN2VL but got " << result.architectureName << std::endl;
  24. std::cout << " 💡 This indicates the fix is not working properly" << std::endl;
  25. } else {
  26. std::cout << " 🎉 SUCCESS: Qwen model correctly detected!" << std::endl;
  27. }
  28. // Show tensor names for debugging
  29. std::cout << "\n🔍 Tensor Analysis (first 10 tensors):" << std::endl;
  30. int count = 0;
  31. for (const auto& tensorName : result.tensorNames) {
  32. if (count >= 10) break;
  33. std::cout << " " << (count + 1) << ". " << tensorName << std::endl;
  34. count++;
  35. }
  36. if (result.tensorNames.size() > 10) {
  37. std::cout << " ... and " << (result.tensorNames.size() - 10) << " more tensors" << std::endl;
  38. }
  39. // Show metadata
  40. std::cout << "\n📄 Metadata:" << std::endl;
  41. for (const auto& [key, value] : result.metadata) {
  42. std::cout << " " << key << ": " << value << std::endl;
  43. }
  44. // Show suggested parameters
  45. if (!result.suggestedParams.empty()) {
  46. std::cout << "\n⚙️ Suggested Parameters:" << std::endl;
  47. for (const auto& [key, value] : result.suggestedParams) {
  48. std::cout << " " << key << ": " << value << std::endl;
  49. }
  50. }
  51. } catch (const std::exception& e) {
  52. std::cout << "❌ Error during model detection: " << e.what() << std::endl;
  53. }
  54. }
  55. int main() {
  56. std::cout << "🧪 Qwen Model Detection Test Suite" << std::endl;
  57. std::cout << "===================================" << std::endl;
  58. // Test with available Qwen models
  59. std::vector<std::string> qwenModelPaths = {
  60. "/data/SD_MODELS/diffusion_models/Qwen-Image-Edit-2509-Q3_K_S.gguf",
  61. "/data/SD_MODELS/diffusion_models/Qwen-Image-Pruning-13b-Q4_0.gguf",
  62. "/data/SD_MODELS/diffusion_models/qwen-image-Q2_K.gguf"
  63. };
  64. int successCount = 0;
  65. int totalTests = 0;
  66. for (const auto& modelPath : qwenModelPaths) {
  67. if (fs::exists(modelPath)) {
  68. totalTests++;
  69. testQwenDetection(modelPath);
  70. // Check if detection was successful
  71. ModelDetectionResult result = ModelDetector::detectModel(modelPath);
  72. if (result.architecture == ModelArchitecture::QWEN2VL) {
  73. successCount++;
  74. }
  75. } else {
  76. std::cout << "\n⚠️ Skipping test for non-existent model: " << modelPath << std::endl;
  77. }
  78. }
  79. // Summary
  80. std::cout << "\n🎯 Test Summary:" << std::endl;
  81. std::cout << " Total Qwen models tested: " << totalTests << std::endl;
  82. std::cout << " Successfully detected as QWEN2VL: " << successCount << std::endl;
  83. std::cout << " Success rate: " << (totalTests > 0 ? (successCount * 100 / totalTests) : 0) << "%" << std::endl;
  84. if (successCount == totalTests && totalTests > 0) {
  85. std::cout << " 🎉 ALL TESTS PASSED! Qwen detection fix is working correctly." << std::endl;
  86. } else if (totalTests > 0) {
  87. std::cout << " ❌ Some tests failed. The fix may need adjustment." << std::endl;
  88. } else {
  89. std::cout << " ⚠️ No Qwen models found to test." << std::endl;
  90. }
  91. std::cout << "\n🏁 Qwen Detection Test Complete!" << std::endl;
  92. return (successCount == totalTests) ? 0 : 1;
  93. }