-
Notifications
You must be signed in to change notification settings - Fork 0
Fix ffnet build for Python 3.13+ and mamba 2.x compatibility #41
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
Merged
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
bf9552d
Add python-docx
mathomp4 c8a5e3c
Update example miniforge version to 25.11.0-1
mathomp4 f055bdc
Tensorflow not for Python 3.14, Basemap for 3.14 only in conda
mathomp4 4f8521e
Update example Python version to 3.14
mathomp4 f1fd3ff
Fix ffnet build for Python 3.13+ and mamba 2.x compatibility
mathomp4 5636980
Update READMEs for Miniforge 26.1.0-0 and Python 3.14
mathomp4 4593e93
Update PyTorch examples for MPS, add torchvision, and prepare 26.1.1-…
mathomp4 23738db
Update install_miniforge.bash
mathomp4 50be101
Apply CodeRabbit review suggestions
mathomp4 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
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,98 @@ | ||
| #!/usr/bin/env python3 | ||
|
|
||
| import torch | ||
| import torch.nn as nn | ||
| import torch.optim as optim | ||
| from torchvision import datasets, transforms | ||
| from torch.utils.data import DataLoader | ||
|
|
||
| print("PyTorch version:", torch.__version__) | ||
| print("CUDA available:", torch.cuda.is_available()) | ||
|
|
||
| # Set device | ||
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") | ||
| print(f"Using device: {device}") | ||
|
|
||
| # Load MNIST dataset | ||
| transform = transforms.Compose([ | ||
| transforms.ToTensor(), # This automatically normalizes to [0, 1] | ||
| ]) | ||
|
|
||
| train_dataset = datasets.MNIST(root='./data', train=True, download=True, transform=transform) | ||
| test_dataset = datasets.MNIST(root='./data', train=False, download=True, transform=transform) | ||
|
|
||
| train_loader = DataLoader(train_dataset, batch_size=32, shuffle=True) | ||
| test_loader = DataLoader(test_dataset, batch_size=32, shuffle=False) | ||
|
|
||
| # Define the model | ||
| model = nn.Sequential( | ||
| nn.Flatten(), | ||
| nn.Linear(28 * 28, 128), | ||
| nn.ReLU(), | ||
| nn.Dropout(0.2), | ||
| nn.Linear(128, 10) | ||
| ).to(device) | ||
|
|
||
| print(model) | ||
|
|
||
| # Loss and optimizer | ||
| criterion = nn.CrossEntropyLoss() # Combines softmax and negative log likelihood | ||
| optimizer = optim.Adam(model.parameters()) | ||
|
|
||
| # Training loop | ||
| epochs = 5 | ||
| for epoch in range(epochs): | ||
| model.train() | ||
| running_loss = 0.0 | ||
| correct = 0 | ||
| total = 0 | ||
|
|
||
| for batch_idx, (data, target) in enumerate(train_loader): | ||
| data, target = data.to(device), target.to(device) | ||
|
|
||
| # Zero the gradients | ||
| optimizer.zero_grad() | ||
|
|
||
| # Forward pass | ||
| output = model(data) | ||
| loss = criterion(output, target) | ||
|
|
||
| # Backward pass and optimize | ||
| loss.backward() | ||
| optimizer.step() | ||
|
|
||
| # Statistics | ||
| running_loss += loss.item() | ||
| _, predicted = torch.max(output.data, 1) | ||
| total += target.size(0) | ||
| correct += (predicted == target).sum().item() | ||
|
|
||
| accuracy = 100 * correct / total | ||
| avg_loss = running_loss / len(train_loader) | ||
| print(f'Epoch {epoch + 1}/{epochs} - Loss: {avg_loss:.4f}, Accuracy: {accuracy:.2f}%') | ||
|
|
||
| # Evaluation | ||
| model.eval() | ||
| correct = 0 | ||
| total = 0 | ||
|
|
||
| with torch.no_grad(): | ||
| for data, target in test_loader: | ||
| data, target = data.to(device), target.to(device) | ||
| output = model(data) | ||
| _, predicted = torch.max(output.data, 1) | ||
| total += target.size(0) | ||
| correct += (predicted == target).sum().item() | ||
|
|
||
| test_accuracy = 100 * correct / total | ||
| print(f'\nTest Accuracy: {test_accuracy:.2f}%') | ||
|
|
||
| # Get probabilities for first 5 test samples | ||
| model.eval() | ||
| with torch.no_grad(): | ||
| test_data, _ = next(iter(test_loader)) | ||
| test_data = test_data[:5].to(device) | ||
| logits = model(test_data) | ||
| probabilities = torch.softmax(logits, dim=1) | ||
| print("\nProbabilities for first 5 test samples:") | ||
| print(probabilities) |
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.
Uh oh!
There was an error while loading. Please reload this page.