-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add universal device support with flash attention fallback #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jryanhaber
wants to merge
4
commits into
sapientinc:main
Choose a base branch
from
Next-AI-Labs-Inc:feature/mps-optimizer-fallback
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
577be7b
Enables device-agnostic execution for MPS/CUDA/CPU
jryanhaber 141856a
Adds initial tag datasets
jryanhaber e1ba521
Add universal device support with flash attention fallback
jryanhaber b3d6be3
Adds classification test script for HRM
jryanhaber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
holon_id,title,description,tags | ||
NAL-001,Next AI Labs,"Next AI Labs is a pioneering center dedicated to developing sentient AI devoted to human flourishing. Focused on research and development across industries via cutting‑edge AI innovations. Suggested next steps include research publications, partnerships, and collaborative projects.",AI Alignment; Human Flourishing; Research Lab | ||
NAL-002,Public Facing Interfaces,Manifesto and other public-facing materials for Next AI Labs.,Public Interfaces; User Vision | ||
NAL-003,Funding for Social Impact Non Profits,Paths to fund an aligned AI lab for human flourishing.,Funding Strategy; Social Impact; Philanthropy | ||
NAL-004,Advisors,Advisory relationships for the lab.,Advisory Network; Partnerships | ||
NAL-005,Relationships,Key collaborators and strategic relationships.,Relationship Building; Partnerships | ||
NAL-006,Personal / Well Being,Founder personal capacity and wellbeing guardrails.,Founder Wellbeing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
tag,description | ||
Leverage Hunting,Identify outsized positive-impact changes and compounding loops. | ||
Churn Reduction,Reduce cancellations and early churn. | ||
Go-To-Market,"Positioning, channels, and activation motion." | ||
User Vision,Narrative and promise communicated to users. | ||
Product-Market Fit,Evidence and work toward strong problem–solution fit. | ||
User Retention,Keep existing users active and engaged. | ||
Automated Emails,"Lifecycle, re‑engagement, and triggered emails." | ||
Memory Injection,Persisting and recalling high‑value user memories in AI flows. | ||
Privacy Promise,Comms and guarantees about data privacy. | ||
Major Email Announcement,Big broadcast email moments / launches. | ||
AI Alignment,Safety/alignment research and practices. | ||
Human Flourishing,Explicit aim to benefit human wellbeing. | ||
Research Lab,Institutional R&D context. | ||
Social Impact,Nonprofit/impact orientation. | ||
Funding Strategy,How to finance the org/initiative. | ||
Philanthropy,Foundation-based grants and gifts. | ||
Government Grants,NSF/DARPA/UKRI/ERC and similar funding. | ||
Corporate Partnerships,Partnerships with tech companies and foundations. | ||
Compute Grants,Credits/GPUs/compute access programs. | ||
Venture Capital,"VC sources, terms, and strategy." | ||
Impact Investing,Investment with explicit social outcomes. | ||
Partnerships,Collaboration and ecosystem relationships. | ||
Public Interfaces,"Manifesto, website, and other public-facing touchpoints." | ||
Advisory Network,"Advisors, mentors, and expert board." | ||
Relationship Building,"Allies, collaborators, and stakeholder ties." | ||
Founder Wellbeing,"Personal capacity, health, and sustainability." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
#!/usr/bin/env python3 | ||
""" | ||
Classification test script for HRM using holon tags data. | ||
Tests the model's ability to classify text using the tag taxonomy. | ||
""" | ||
|
||
import pandas as pd | ||
import torch | ||
import os | ||
import sys | ||
from pathlib import Path | ||
|
||
def get_device(): | ||
"""Universal device detection for HRM testing""" | ||
if torch.backends.mps.is_available(): | ||
return torch.device("mps") | ||
elif torch.cuda.is_available(): | ||
return torch.device("cuda") | ||
else: | ||
return torch.device("cpu") | ||
|
||
def load_classification_data(): | ||
"""Load holon tags and tags master for classification testing""" | ||
dataset_path = Path("dataset") | ||
|
||
# Load holon tags (the data to classify) | ||
holon_tags = pd.read_csv(dataset_path / "holon_tags.csv") | ||
print(f"Loaded {len(holon_tags)} holon entries") | ||
|
||
# Load tags master (the classification taxonomy) | ||
tags_master = pd.read_csv(dataset_path / "tags_master.csv") | ||
print(f"Loaded {len(tags_master)} tag definitions") | ||
|
||
return holon_tags, tags_master | ||
|
||
def prepare_classification_examples(): | ||
"""Prepare text examples for classification testing""" | ||
holon_tags, tags_master = load_classification_data() | ||
|
||
examples = [] | ||
for _, row in holon_tags.iterrows(): | ||
example = { | ||
'id': row['holon_id'], | ||
'title': row['title'], | ||
'description': row['description'], | ||
'true_tags': row['tags'].split('; ') if pd.notna(row['tags']) else [], | ||
'full_text': f"{row['title']}: {row['description']}" | ||
} | ||
examples.append(example) | ||
|
||
print(f"Prepared {len(examples)} classification examples") | ||
return examples, tags_master | ||
|
||
def test_device_compatibility(): | ||
"""Test basic tensor operations on the detected device""" | ||
device = get_device() | ||
print(f"Testing device compatibility: {device}") | ||
|
||
try: | ||
# Test tensor creation and operations | ||
x = torch.randn(10, 10).to(device) | ||
y = torch.randn(10, 10).to(device) | ||
z = torch.matmul(x, y) | ||
|
||
print(f"✅ Device test passed - tensor operations work on {device}") | ||
return True | ||
except Exception as e: | ||
print(f"❌ Device test failed: {e}") | ||
return False | ||
|
||
def run_classification_test(): | ||
"""Main classification test runner""" | ||
print("=" * 60) | ||
print("HRM CLASSIFICATION TEST") | ||
print("=" * 60) | ||
|
||
# Test device compatibility | ||
if not test_device_compatibility(): | ||
return False | ||
|
||
# Load and prepare data | ||
try: | ||
examples, tags_master = prepare_classification_examples() | ||
|
||
print(f"\\nClassification Test Data Summary:") | ||
print(f"- Examples to classify: {len(examples)}") | ||
print(f"- Available tags: {len(tags_master)}") | ||
print(f"- Device: {get_device()}") | ||
|
||
# Show sample data | ||
print(f"\\nSample classification example:") | ||
sample = examples[0] | ||
print(f"ID: {sample['id']}") | ||
print(f"Title: {sample['title']}") | ||
print(f"Description: {sample['description'][:100]}...") | ||
print(f"True tags: {sample['true_tags']}") | ||
|
||
print(f"\\nAvailable tag categories:") | ||
for _, tag in tags_master.head(10).iterrows(): | ||
print(f"- {tag['tag']}: {tag['description']}") | ||
|
||
print(f"\\n✅ Classification test data prepared successfully!") | ||
print(f"\\n📋 NEXT STEPS:") | ||
print(f"1. Load a pretrained HRM model checkpoint") | ||
print(f"2. Run inference on the prepared examples") | ||
print(f"3. Compare predicted tags vs true tags") | ||
|
||
return True | ||
|
||
except Exception as e: | ||
print(f"❌ Classification test failed: {e}") | ||
return False | ||
|
||
if __name__ == "__main__": | ||
success = run_classification_test() | ||
sys.exit(0 if success else 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python3 | ||
"""Simple test script to verify device detection works correctly.""" | ||
|
||
def get_device(): | ||
import torch | ||
if torch.backends.mps.is_available(): | ||
return torch.device("mps") | ||
elif torch.cuda.is_available(): | ||
return torch.device("cuda") | ||
else: | ||
return torch.device("cpu") | ||
|
||
if __name__ == "__main__": | ||
device = get_device() | ||
print(f"Using device: {device}") | ||
|
||
# Test tensor creation and basic operations | ||
import torch | ||
x = torch.randn(3, 3).to(device) | ||
y = torch.randn(3, 3).to(device) | ||
z = x + y | ||
print(f"Tensor operation successful on {device}") | ||
print(f"Result shape: {z.shape}") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why
\\n
? Maybe\n
?