Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jun 29, 2025

This PR adds comprehensive environment validation to provide immediate feedback when users attempt to run model tests on unsupported configurations, helping them understand limitations and avoid confusion when tests fail.

Problem

Users running model tests on unsupported environments (e.g., macOS without NVIDIA support, incompatible Python versions) would encounter confusing failures without clear guidance on what was wrong or how to fix it.

Solution

Added early environment validation that checks for:

  1. Python Version Compatibility

    • Hard fails for Python < 3.8 with clear error message
    • Shows warnings for Python < 3.9 for optimal compatibility
  2. Platform-Specific GPU Support

    • Detects environments without NVIDIA GPU support for GPU-requiring models
    • Analyzes model configuration using num_accelerators field to determine GPU requirements
    • Provides different behavior for GPU vs CPU-only models
  3. Docker Availability

    • Warns when Docker is not available for container-based testing

Key Features

  • Early Validation: Runs before any heavy model operations to fail fast
  • Smart Detection: Analyzes model configuration to determine actual requirements using num_accelerators field
  • Clear Messaging: Provides actionable error messages with specific recommendations
  • Graceful Degradation: Warnings for non-critical issues, errors for blocking issues

Example Output

For a GPU model on an environment without NVIDIA support:

[INFO] Validating test environment...
[ERROR] ❌ Environment validation failed:
[ERROR]   1. Your current environment i.e. 'darwin (macOS)' does not have NVIDIA GPU support. Your model configuration requires GPU support. Please test on a environment with NVIDIA GPU support, or modify your model configuration to use CPU-only inference.
[ERROR] 
💡 To resolve these issues:
   • Update your Python version if needed
   • Use a system with NVIDIA drivers for GPU models
   • Modify your model configuration for CPU-only inference
   • Check the Clarifai documentation for supported environments

Changes Made

  • Modified: clarifai/runners/models/model_run_locally.py

    • Added _validate_test_environment() method with comprehensive checks
    • GPU requirement detection based on num_accelerators field (if not 0, GPU is required)
    • Integrated validation call early in main() function
  • Added: tests/runners/test_environment_validation.py

    • Complete test suite with 9 test cases covering different scenarios
    • Tests for Python version validation, platform detection, GPU requirements
    • Integration tests ensuring validation is called in main flow
    • Specific tests for num_accelerators detection logic

Testing

All tests pass, including:

  • ✅ Python version validation (current version passes, old versions fail)
  • ✅ GPU model detection via num_accelerators field (fails appropriately without GPU)
  • ✅ CPU model detection (passes with warnings)
  • ✅ Linux validation (passes)
  • ✅ Integration with main function
  • ✅ Early exit behavior on validation failure
  • ✅ Comprehensive num_accelerators logic validation

Fixes #657.

[!WARNING]


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Co-authored-by: srikanthbachala20 <170492893+srikanthbachala20@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement immediate feedback for unsupported test environments for models deployment Implement immediate feedback for unsupported test environments for models deployment Jun 29, 2025
Copilot AI requested a review from srikanthbachala20 June 29, 2025 11:21
@ackizilkale
Copy link
Contributor

@srikanthbachala20 is this ready to review?

Enhanced GPU requirement detection in environment validation to also check for num_accelerators field in inference_compute_info. If num_accelerators is not 0, requires_gpu is set to True, providing more comprehensive GPU requirement detection as requested in code review.

Co-authored-by: srikanthbachala20 <170492893+srikanthbachala20@users.noreply.github.com>
Updated the environment validation tests to align with the current implementation in model_run_locally.py:
- Removed accelerator_type from GPU model fixture since current logic only checks num_accelerators
- Added comprehensive test for num_accelerators detection logic
- Added test for CPU-only models (num_accelerators=0)
- Updated test descriptions to match current behavior
- Fixed import issues for better code organization

Tests now properly validate the simplified GPU detection logic that only checks num_accelerators field.

Co-authored-by: srikanthbachala20 <170492893+srikanthbachala20@users.noreply.github.com>
@srikanthbachala20 srikanthbachala20 removed their request for review October 25, 2025 10:36
@srikanthbachala20 srikanthbachala20 marked this pull request as ready for review October 25, 2025 10:43
@srikanthbachala20 srikanthbachala20 requested review from a team and Copilot October 25, 2025 10:43
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements comprehensive environment validation for model testing to provide immediate feedback when users attempt to run tests on unsupported configurations. The validation checks Python version compatibility, platform-specific GPU support based on model requirements, and Docker availability, failing fast with clear error messages before expensive setup operations.

Key changes:

  • Added _validate_test_environment() method that performs early validation checks
  • Integrated validation call at the start of main() function before any setup operations
  • GPU requirement detection based on num_accelerators configuration field

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
clarifai/runners/models/model_run_locally.py Added _validate_test_environment() method with Python version, GPU availability, and Docker checks; integrated validation call in main()
tests/runners/test_environment_validation.py Comprehensive test suite covering Python version validation, GPU/CPU model detection, platform validation, and integration with main function

@christineyu123
Copy link
Contributor

Just curious, the added function _validate_test_environment will be triggered under what scenarios, clarifai model local-test or/and clarifai model local-runner? Would appreciate if you can list the CLIs that are going to trigger this validation so we can bear in mind in future. Thanks

@github-actions
Copy link

Code Coverage

Package Line Rate Health
clarifai 45%
clarifai.cli 44%
clarifai.cli.templates 33%
clarifai.client 67%
clarifai.client.auth 67%
clarifai.constants 100%
clarifai.datasets 100%
clarifai.datasets.export 80%
clarifai.datasets.upload 75%
clarifai.datasets.upload.loaders 37%
clarifai.models 100%
clarifai.modules 0%
clarifai.rag 72%
clarifai.runners 53%
clarifai.runners.models 59%
clarifai.runners.pipeline_steps 41%
clarifai.runners.pipelines 70%
clarifai.runners.utils 63%
clarifai.runners.utils.data_types 72%
clarifai.schema 100%
clarifai.urls 60%
clarifai.utils 60%
clarifai.utils.evaluation 67%
clarifai.workflows 95%
Summary 62% (8209 / 13325)

Minimum allowed line rate is 50%

@srikanthbachala20 srikanthbachala20 merged commit 836a93a into master Oct 29, 2025
12 checks passed
@srikanthbachala20 srikanthbachala20 deleted the copilot/fix-657 branch October 29, 2025 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

Implement immediate feedback for unsupported test environments for models deployment

4 participants