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
| def self_attn_fwd(...): | |
| # loading sample len | |
| seq_len = ... | |
| # running qk^T max (initialized by -inf) | |
| m_i = tl.zeros([TILE_Q_SIZE], dtype=tl.float32) - float("inf") | |
| # current softmax denominator | |
| l_i = tl.zeros([TILE_Q_SIZE], dtype=tl.float32) |
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
| row_minus_max = row - tl.max(row, axis=1, keep_dims=True) | |
| row_minus_max = tl.where(cols_mask, row_minus_max, -float('inf')) | |
| numerator = tl.exp(row_minus_max) | |
| denominator = tl.sum(numerator, axis=1, keep_dims=True) | |
| softmax_output = numerator / denominator |
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
| import torch | |
| import triton | |
| import triton.language as tl | |
| @triton.autotune( | |
| configs=[ | |
| triton.Config( | |
| kwargs=dict( | |
| BLOCK_SIZE_ROWS=BLOCK_SIZE_ROWS, |
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
| import torch | |
| # Our softmax function in PyTorch land | |
| def softmax_pytorch(x): | |
| # Avoid numerical instability by subtracting max | |
| x_max = torch.max(x, dim=-1, keepdim=True).values | |
| x_exp = torch.exp(x - x_max) | |
| return x_exp / torch.sum(x_exp, dim=-1, keepdim=True) | |
| # Let's compile it with torch.compile |
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
| row_minus_max = row - tl.max(row, axis=1, keep_dims=True) | |
| row_minus_max = tl.where(cols_mask, row_minus_max, -float('inf')) | |
| numerator = tl.exp(row_minus_max) | |
| denominator = tl.sum(numerator, axis=1, keep_dims=True) | |
| softmax_output = numerator / denominator |
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
| import torch | |
| import triton | |
| import triton.language as tl | |
| @triton.autotune( | |
| configs=[ | |
| triton.Config( | |
| kwargs=dict( | |
| BLOCK_SIZE_ROWS=BLOCK_SIZE_ROWS, |
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
| import torch | |
| # Our softmax function in PyTorch land | |
| def softmax_pytorch(x): | |
| # Avoid numerical instability by subtracting max | |
| x_max = torch.max(x, dim=-1, keepdim=True).values | |
| x_exp = torch.exp(x - x_max) | |
| return x_exp / torch.sum(x_exp, dim=-1, keepdim=True) | |
| # Let's compile it with torch.compile |
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
| import numpy as np | |
| import scipy | |
| def ravel_image(img): | |
| """ | |
| Разворачивает изображения в одномерный массив с учетом батча | |
| """ | |
| assert 1 < len(img.shape) < 4 |
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
| name: Task0 tests | |
| on: [push] | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| python-version: [3.9] |
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
| class Person { | |
| let name: String | |
| init(name: String) { self.name = name } | |
| var apartment: Apartment? | |
| deinit { print("\(name) is being deinitialized") } | |
| } | |
| class Apartment { | |
| let unit: String | |
| init(unit: String) { self.unit = unit } |
NewerOlder