ultralytics / ultralytics

NEW - YOLOv8 🚀 in PyTorch > ONNX > OpenVINO > CoreML > TFLite
https://docs.ultralytics.com
GNU Affero General Public License v3.0
26.51k stars 5.28k forks source link

Sudden FPS drop on a MacBook Pro with M3 Max #14009

Open Pyotryeet opened 3 weeks ago

Pyotryeet commented 3 weeks ago

Search before asking

Question

I have a MacBook Pro with M3 Max chip, when I run the python code I wrote to track an obejct with a trained yolov8 large model at first I get around 43 fps after 10 or 15 or so the fps drops to 10-15 and sometimes it goes back up, and it doesnt use the whole GPU. Help me please

Additional

No response

github-actions[bot] commented 3 weeks ago

👋 Hello @Pyotryeet, thank you for your interest in Ultralytics YOLOv8 🚀! We recommend a visit to the Docs for new users where you can find many Python and CLI usage examples and where many of the most common questions may already be answered.

If this is a 🐛 Bug Report, please provide a minimum reproducible example to help us debug it.

If this is a custom training ❓ Question, please provide as much information as possible, including dataset image examples and training logs, and verify you are following our Tips for Best Training Results.

Join the vibrant Ultralytics Discord 🎧 community for real-time conversations and collaborations. This platform offers a perfect space to inquire, showcase your work, and connect with fellow Ultralytics users.

Install

Pip install the ultralytics package including all requirements in a Python>=3.8 environment with PyTorch>=1.8.

pip install ultralytics

Environments

YOLOv8 may be run in any of the following up-to-date verified environments (with all dependencies including CUDA/CUDNN, Python and PyTorch preinstalled):

Status

Ultralytics CI

If this badge is green, all Ultralytics CI tests are currently passing. CI tests verify correct operation of all YOLOv8 Modes and Tasks on macOS, Windows, and Ubuntu every 24 hours and on every commit.

Y-T-G commented 3 weeks ago

Throttling probably

glenn-jocher commented 3 weeks ago

@Y-T-G hello,

Thank you for reaching out and providing details about your issue. It sounds like you might be experiencing thermal throttling, which can occur when the system reduces performance to manage heat. Here are a few steps you can take to diagnose and potentially mitigate the issue:

  1. Monitor System Resources: Use macOS's built-in Activity Monitor or third-party tools to monitor CPU and GPU usage, temperature, and other system metrics. This can help confirm if thermal throttling is occurring.

  2. Update Software: Ensure you are using the latest versions of Ultralytics YOLO, PyTorch, and any other dependencies. Sometimes performance issues are resolved in newer releases.

  3. Optimize Code: Make sure your code is optimized for performance. For example, you can enable mixed precision training or inference using the amp argument in YOLOv8, which can help reduce the load on your GPU:

    from ultralytics import YOLO
    
    model = YOLO('yolov8l.pt')
    results = model.track(source='your_video.mp4', device='mps', amp=True)
  4. Cooling Solutions: Ensure your MacBook Pro has adequate ventilation. Using a cooling pad or elevating the laptop can help improve airflow and reduce thermal throttling.

  5. Batch Processing: If you are processing a video, consider reducing the batch size or frame rate to lessen the load on your system.

If the issue persists, providing a minimum reproducible example would be very helpful for further diagnosis. You can find guidance on creating one here: Minimum Reproducible Example.

Feel free to share any additional details or updates. We're here to help!

Pyotryeet commented 3 weeks ago

No throttling, GPU usage is barely at 20 percent. I have 40 GPU cores, and my computer runs at 55 degrees celcius. Everything is up to date, I even reinstalled macos and all my libraries and redownloaded python many times but no help. Tracking starts with around 40 fps and GPU usage is 20-25% at that moment, actually GPU usage never surpasses 25%, so its not a system problem.

glenn-jocher commented 3 weeks ago

Hello @Pyotryeet-G,

Thank you for the additional information. Given that your system is not overheating and GPU usage remains low, it seems the issue might be related to software or configuration rather than hardware limitations.

Here are a few suggestions to further diagnose and potentially resolve the issue:

  1. Memory Management: Ensure that memory usage is not causing the slowdown. You can monitor memory usage using Activity Monitor or similar tools. If memory usage spikes, it could lead to performance drops.

  2. Batch Size and Frame Rate: Experiment with different batch sizes and frame rates to see if they impact performance. Sometimes, smaller batch sizes can help maintain consistent FPS.

  3. Mixed Precision: If you haven't already, try enabling mixed precision inference to reduce the computational load:

    from ultralytics import YOLO
    
    model = YOLO('yolov8l.pt')
    results = model.track(source='your_video.mp4', device='mps', amp=True)
  4. Profiling: Use profiling tools to identify bottlenecks in your code. Tools like cProfile or line_profiler can help pinpoint where the slowdown occurs.

  5. Asynchronous Processing: If you are processing video frames, consider using asynchronous processing to keep the pipeline moving smoothly.

  6. Example Code: If possible, please provide a minimal reproducible example of your code. This will help us better understand the context and provide more targeted assistance. You can find guidance on creating one here: Minimum Reproducible Example.

Your detailed observations are very helpful, and we appreciate your patience. Let's work together to get this resolved! 😊