Skip to content

Commit

Permalink
fix automatic einsum segmentation
Browse files Browse the repository at this point in the history
  • Loading branch information
lehner committed Feb 28, 2024
1 parent c5d55fb commit d5b9adf
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/gpt/core/einsum.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,19 @@ def process_indices(names, values, epsilon_tensors, sign0):
else:
index_value[j] = 0

# now sort by target index
code = sorted(code, key = lambda c: c[1])

Check failure on line 169 in lib/gpt/core/einsum.py

View workflow job for this annotation

GitHub Actions / lint

E251:unexpected spaces around keyword / parameter equals

Check failure on line 169 in lib/gpt/core/einsum.py

View workflow job for this annotation

GitHub Actions / lint

E251:unexpected spaces around keyword / parameter equals

# now verify that segmentation works
assert len(code) % nsegment == 0
use_segmentation = all([len(set([c[1] for c in code[i:i+nsegment]])) == 1 for i in range(0, len(code), nsegment)])

Check failure on line 173 in lib/gpt/core/einsum.py

View workflow job for this annotation

GitHub Actions / lint

E226:missing whitespace around arithmetic operator
if not use_segmentation:
nsegment = 1

Check failure on line 176 in lib/gpt/core/einsum.py

View workflow job for this annotation

GitHub Actions / lint

W293:blank line contains whitespace
# create segmentation
segments = [(len(code) // nsegment, nsegment)]

# and tensor
ein = g.stencil.tensor(tensors_destination[0], [(0, 0, 0, 0)], code, segments)

def exec(*src):
Expand Down

0 comments on commit d5b9adf

Please sign in to comment.