Skip to content

Commit

Permalink
Merge pull request #3 from hadriansecurity/fix_oom_for_large_n
Browse files Browse the repository at this point in the history
use a smaller batch size for even less memory usage
  • Loading branch information
klaasmeinke authored Aug 18, 2024
2 parents c2786b6 + 153801f commit ce60364
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "subwiz"
version = "0.1.1"
version = "0.1.2"
description = "A recon tool that uses AI to predict subdomains. Then returns those that resolve."
readme = "README.md"
requires-python = ">=3.7"
Expand Down
7 changes: 5 additions & 2 deletions subwiz/model.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"""
This code is largely copied from the nanogpt repository by Andrej Karpathy.
https://github.com/karpathy/nanoGPT
Full definition of a GPT Language Model, all of it in this single file.
References:
1) the official GPT-2 TensorFlow implementation released by OpenAI:
Expand Down Expand Up @@ -308,11 +311,11 @@ def generate(
sequences = sequences[:, -self.config.block_size :]

# inference the model in batches
batch_size = 500
batch_size = 8
logits, _ = self(sequences[:batch_size])
for j in range(batch_size, len(sequences), batch_size):
new_logits, _ = self(sequences[j : j + batch_size])
logits = torch.cat(tensors=(new_logits, logits), dim=1)
logits = torch.cat(tensors=(new_logits, logits), dim=0)
logits = logits.squeeze(1)

# take N most probable next tokens for each sequence
Expand Down

0 comments on commit ce60364

Please sign in to comment.