Skip to content

Refactor/strict bool for use flash attn#179

Merged
ncfrey merged 5 commits intoprescient-design:mainfrom
young-su-ko:refactor/strict-bool-for-use-flash-attn
Aug 5, 2025
Merged

Refactor/strict bool for use flash attn#179
ncfrey merged 5 commits intoprescient-design:mainfrom
young-su-ko:refactor/strict-bool-for-use-flash-attn

Conversation

@young-su-ko
Copy link
Contributor

Description

Replaced all instances of the tri-state Boolean use_flash_attn: bool | None = None to be strictly a bool. Addresses #170.

model/_ume.py

  • Previously, use_flash_attn = None implied that the user had no preference, and flash attention would be enabled automatically if device == "cuda".
  • This logic is now replaced with an explicit default: use_flash_attn: bool = True
  • If use_flash_attn is True but flash attention is not available (device != "cuda"), a warning is logged and use_flash_attn is overridden to False.

tests/model/test__ume.py

  • Updated test_from_pretrained to reflect that use_flash_attn = True is now the default.

evaluation/dgeb_*.py

  • In dgeb_adapter.py and dgeb_runner.py, the default is now use_flash_attn = True
    • If flash attention is unavailable, it is set to False and a warning is logged.
    • The adapter uses the more robust _check_flash_attention_available method from UMEAdapterDGEB to check whether flash attention can be enabled (compared to just device != "cuda")
  • In dgeb_mock_adapter.py and dgeb_mock_runner.py, the default is set to False as flash attention is explicitly unused in the mock implementation.

Type of Change

  • Bug fix
  • New feature
  • Documentation update
  • Performance improvement
  • Code refactoring

@ncfrey ncfrey requested a review from Copilot August 4, 2025 15:26
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 refactors the use_flash_attn parameter from a tri-state boolean (bool | None) to a strict boolean (bool) across the codebase. The change eliminates the implicit auto-detection logic where None meant "auto-detect based on device" and replaces it with explicit defaults and warning messages when flash attention is requested but unavailable.

Key changes:

  • Updated use_flash_attn parameter from bool | None to bool with appropriate defaults
  • Replaced implicit auto-detection logic with explicit warning and override behavior
  • Set different defaults for production code (True) vs mock implementations (False)

Reviewed Changes

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

Show a summary per file
File Description
src/lobster/model/_ume.py Changed use_flash_attn parameter to strict bool with default True, added warning when flash attention is requested but CUDA unavailable
tests/lobster/model/test__ume.py Updated test to reflect new default value of True for use_flash_attn
src/lobster/evaluation/dgeb_runner.py Changed parameter to strict bool with default True, removed conditional logic in main function
src/lobster/evaluation/dgeb_mock_runner.py Changed parameter to strict bool with default False for mock implementation
src/lobster/evaluation/dgeb_mock_adapter.py Updated mock adapter to use strict bool with default False
src/lobster/evaluation/dgeb_adapter.py Refactored flash attention detection logic to use strict bool with default True

load_func=UME.load_from_checkpoint,
device=None,
use_flash_attn=None,
use_flash_attn=True,
Copy link
Contributor

Choose a reason for hiding this comment

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

we might want to change this to False to run on CPU runners

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, just pushed a new commit switching to use_flash_attn=False for this test!

@ncfrey
Copy link
Contributor

ncfrey commented Aug 5, 2025

@young-su-ko looks good!

@ncfrey ncfrey merged commit 2c14e6d into prescient-design:main Aug 5, 2025
4 checks passed
@young-su-ko young-su-ko mentioned this pull request Aug 5, 2025
1 task
@young-su-ko young-su-ko deleted the refactor/strict-bool-for-use-flash-attn branch August 5, 2025 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants