Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions My First Malware.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"metadata": {},
"outputs": [],
"source": [
"use_cuda = True"
"use_cuda = True\n",
"device = torch.device(\"cuda\" if use_cuda and torch.cuda.is_available() else \"cpu\")"
]
},
{
Expand Down Expand Up @@ -1824,7 +1825,7 @@
"\n",
" def forward(self, g, feature):\n",
" # Initialize the node features with h.\n",
" g.ndata['h'] = feature.to(torch.device(\"cuda:1\" if torch.cuda.is_available() and use_cuda is True else \"cpu\"))\n",
" g.ndata['h'] = feature.to(device)\n",
" g.update_all(\n",
" message_func = fn.copy_src(src='h', out='m'), \n",
" reduce_func = fn.sum(msg='m', out='h')\n",
Expand Down Expand Up @@ -1916,7 +1917,7 @@
" def __init__(self, learning_rate, model, data_loader, k_fold_number_splits, accuracy_samples, loss_samples):\n",
" super(Trainer, self).__init__()\n",
" self.learning_rate = learning_rate\n",
" self.device = torch.device(\"cuda:1\" if torch.cuda.is_available() and use_cuda is True else \"cpu\")\n",
" self.device = device\n",
" self.model = model.to(self.device)\n",
" self.data_loader = data_loader\n",
" self.loss_func = nn.NLLLoss()\n",
Expand Down
11 changes: 5 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,15 @@ For large datasets this step is slow (Androguard can take 10–60 seconds per AP

### GPU configuration

The notebook sets `use_cuda = True` and targets `cuda:1`. If you only have one GPU (device `cuda:0`) or want to use CPU, edit the relevant line in the second cell:
The notebook sets `use_cuda = True` in the second cell and derives a `device` variable from it:

```python
# Single GPU
device = torch.device("cuda:0" if use_cuda and torch.cuda.is_available() else "cpu")

# CPU only
use_cuda = False
use_cuda = True
device = torch.device("cuda" if use_cuda and torch.cuda.is_available() else "cpu")
```

This selects `cuda:0` when a GPU is available, or falls back to CPU automatically. To force CPU-only execution, change `use_cuda = False` in the second cell.

## Results

Trained on the AMD dataset with the default hyperparameters:
Expand Down