Skip to content

Fix/yoloe text model attribute in yoloe trainer from scratch#23428

Merged
Laughing-q merged 2 commits intoultralytics:mainfrom
ShuaiLYU:fix/yoloe-text-model-attribute-in-YOLOETrainerFromScratch
Jan 26, 2026
Merged

Fix/yoloe text model attribute in yoloe trainer from scratch#23428
Laughing-q merged 2 commits intoultralytics:mainfrom
ShuaiLYU:fix/yoloe-text-model-attribute-in-YOLOETrainerFromScratch

Conversation

@ShuaiLYU
Copy link
Copy Markdown
Contributor

@ShuaiLYU ShuaiLYU commented Jan 26, 2026

This pull request updates the way the text model is referenced and used in the generate_text_embeddings method, improving clarity and robustness. The most important change is using the unwrapped model's text_model attribute directly, which helps avoid ambiguity and potential errors when handling different model wrappers.

Improvements to model handling:

  • Changed the model reference in generate_text_embeddings from a hardcoded string to dynamically use unwrap_model(self.model).text_model, ensuring the correct model is used and improving maintainability.<!--
    Thank you 🙏 for your contribution to Ultralytics 🚀! Your effort in enhancing our repositories is greatly appreciated. To streamline the process and assist us in integrating your Pull Request (PR) effectively, please follow these steps:
  1. Check for Existing Contributions: Before submitting, kindly explore existing PRs to ensure your contribution is unique and complementary.

  2. Link Related Issues: If your PR addresses an open issue, please link it in your submission. This helps us better understand the context and impact of your contribution.

  3. Elaborate Your Changes: Clearly articulate the purpose of your PR. Whether it's a bug fix or a new feature, a detailed description aids in a smoother integration process.

  4. Ultralytics Contributor License Agreement (CLA): To uphold the quality and integrity of our project, we require all contributors to sign the CLA. Please confirm your agreement by commenting below:

    I have read the CLA Document and I sign the CLA

For more detailed guidance and best practices on contributing, refer to our ✅ Contributing Guide. Your adherence to these guidelines ensures a faster and more effective review process.
-->

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

Fix YOLOE trainer text-embedding cache key to use the actual configured text_model instead of a hardcoded string 🧠

📊 Key Changes

  • Updated generate_text_embeddings() to derive model from unwrap_model(self.model).text_model rather than the hardcoded "mobileclip:blt"
  • Cache filename now reflects the active text model, preventing cache collisions across different configurations 📦
  • Removed a redundant assert self.model is not None before calling unwrap_model(self.model).get_text_pe(...)

🎯 Purpose & Impact

  • Ensures text-embedding caching is correct when training YOLOE from scratch with different text model settings ✅
  • Avoids silently reusing incompatible cached embeddings that could degrade training quality or cause confusing behavior 🔍
  • Improves robustness/consistency by relying on the model’s actual attributes rather than constants 🛠️

@UltralyticsAssistant UltralyticsAssistant added bug Something isn't working as intended in the official Ultralytics package. fixed Bug has been resolved python Pull requests that update python code labels Jan 26, 2026
@UltralyticsAssistant
Copy link
Copy Markdown
Member

👋 Hello @ShuaiLYU, thank you for submitting a ultralytics/ultralytics 🚀 PR! To ensure a seamless integration of your work, please review the following checklist:

-✅ Define a Purpose: Clearly explain the purpose of your fix or feature in your PR description, and link to any relevant issues. Ensure your commit messages are clear, concise, and adhere to the project's conventions.
-✅ Synchronize with Source: Confirm your PR is synchronized with the ultralytics/ultralytics main branch. If it's behind, update it by clicking the 'Update branch' button or by running git pull and git merge main locally.
-✅ Ensure CI Checks Pass: Verify all Ultralytics Continuous Integration (CI) checks are passing. If any checks fail, please address the issues.
-✅ Update Documentation: Update the relevant documentation for any new or modified features.
-✅ Add Tests: If applicable, include or update tests to cover your changes, and confirm that all tests are passing.
-✅ Sign the CLA: Please ensure you have signed our Contributor License Agreement if this is your first Ultralytics PR by writing "I have read the CLA Document and I sign the CLA" in a new message.
-✅ Minimize Changes: Limit your changes to the minimum necessary for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." — Bruce Lee

For more guidance, please refer to our Contributing Guide. This is an automated note 🤖—an engineer will assist shortly. Don’t hesitate to leave a comment if you have any questions. Thank you for contributing to Ultralytics! 🚀

Copy link
Copy Markdown
Member

@UltralyticsAssistant UltralyticsAssistant left a comment

Choose a reason for hiding this comment

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

🔍 PR Review

Made with ❤️ by Ultralytics Actions

PR looks clean. The changes align with the intended behavior and don’t introduce any obvious issues.

@codecov
Copy link
Copy Markdown

codecov bot commented Jan 26, 2026

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultralytics/models/yolo/yoloe/train.py 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown
Member

@Laughing-q Laughing-q left a comment

Choose a reason for hiding this comment

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

@ShuaiLYU nice fix!

@Laughing-q Laughing-q merged commit 9fabd7f into ultralytics:main Jan 26, 2026
19 checks passed
kuazhangxiaoai pushed a commit to kuazhangxiaoai/ultralytics-semantic-segment that referenced this pull request Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working as intended in the official Ultralytics package. fixed Bug has been resolved python Pull requests that update python code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants