project_name
string
class_name
string
class_modifiers
string
class_implements
int64
class_extends
int64
function_name
string
function_body
string
cyclomatic_complexity
int64
NLOC
int64
num_parameter
int64
num_token
int64
num_variable
int64
start_line
int64
end_line
int64
function_index
int64
function_params
string
function_variable
string
function_return_type
string
function_body_line_type
string
function_num_functions
int64
function_num_lines
int64
outgoing_function_count
int64
outgoing_function_names
string
incoming_function_count
int64
incoming_function_names
string
lexical_representation
string
pytorch_ao
public
public
0
0
generate_crop_boxes.crop_len
def crop_len(orig_len, n_crops, overlap):return int(math.ceil((overlap * (n_crops - 1) + orig_len) / n_crops))
1
2
3
31
0
388
389
388
null
[]
None
null
0
0
0
null
0
null
The function (generate_crop_boxes.crop_len) defined within the public class called public.The function start at line 388 and ends at 389. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [388.0] and does not return any value..
pytorch_ao
public
public
0
0
generate_crop_boxes
def generate_crop_boxes(im_size: Tuple[int, ...], n_layers: int, overlap_ratio: float) -> Tuple[List[List[int]], List[int]]:"""Generates a list of crop boxes of different sizes. Each layerhas (2**i)**2 boxes for the ith layer."""crop_boxes, layer_idxs = [], []im_h, im_w = im_sizeshort_side = min(im_h, im_w)# Original i...
5
21
3
229
8
373
407
373
null
['crop_box_x0', 'crop_w', 'crop_h', 'short_side', 'box', 'n_crops_per_side', 'crop_box_y0', 'overlap']
None
null
0
0
0
null
0
null
The function (generate_crop_boxes) defined within the public class called public.The function start at line 373 and ends at 407. It contains 21 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [373.0] and does not return any value..
pytorch_ao
public
public
0
0
uncrop_boxes_xyxy
def uncrop_boxes_xyxy(boxes: torch.Tensor, crop_box: List[int]) -> torch.Tensor:x0, y0, _, _ = crop_boxoffset = torch.tensor([[x0, y0, x0, y0]]).pin_memory()offset = offset.to(device=boxes.device, non_blocking=True)# Check if boxes has a channel dimensionif len(boxes.shape) == 3:offset = offset.unsqueeze(1)return boxes...
2
7
2
89
1
410
417
410
null
['offset']
None
null
0
0
0
null
0
null
The function (uncrop_boxes_xyxy) defined within the public class called public.The function start at line 410 and ends at 417. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [410.0] and does not return any value..
pytorch_ao
public
public
0
0
uncrop_points
def uncrop_points(points: torch.Tensor, crop_box: List[int]) -> torch.Tensor:x0, y0, _, _ = crop_boxoffset = torch.tensor([[x0, y0]]).pin_memory()offset = offset.to(device=points.device, non_blocking=True)# Check if points has a channel dimensionif len(points.shape) == 3:offset = offset.unsqueeze(1)return points + offs...
2
7
2
85
1
420
427
420
null
['offset']
None
null
0
0
0
null
0
null
The function (uncrop_points) defined within the public class called public.The function start at line 420 and ends at 427. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [420.0] and does not return any value..
pytorch_ao
public
public
0
0
uncrop_masks
def uncrop_masks(masks: torch.Tensor, crop_box: List[int], orig_h: int, orig_w: int) -> torch.Tensor:x0, y0, x1, y1 = crop_boxif x0 == 0 and y0 == 0 and x1 == orig_w and y1 == orig_h:return masks# Coordinate transform maskspad_x, pad_y = orig_w - (x1 - x0), orig_h - (y1 - y0)pad = (x0, pad_x - x0, y0, pad_y - y0)return...
5
9
4
107
1
430
439
430
null
['pad']
None
null
0
0
0
null
0
null
The function (uncrop_masks) defined within the public class called public.The function start at line 430 and ends at 439. It contains 9 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [430.0] and does not return any value..
pytorch_ao
public
public
0
0
remove_small_regions
def remove_small_regions(mask: np.ndarray, area_thresh: float, mode: str) -> Tuple[np.ndarray, bool]:"""Removes small disconnected regions and holes in a mask. Returns themask and an indicator of if the mask has been modified."""import cv2# type: ignoreassert mode in ["holes", "islands"]correct_holes = mode == "holes"w...
8
19
3
182
6
442
466
442
null
['fill_labels', 'sizes', 'small_regions', 'mask', 'working_mask', 'correct_holes']
None
null
0
0
0
null
0
null
The function (remove_small_regions) defined within the public class called public.The function start at line 442 and ends at 466. It contains 19 lines of code and it has a cyclomatic complexity of 8. It takes 3 parameters, represented as [442.0] and does not return any value..
pytorch_ao
public
public
0
0
coco_encode_rle
def coco_encode_rle(uncompressed_rle: Dict[str, Any]) -> Dict[str, Any]:from pycocotools import mask as mask_utils# type: ignoreh, w = uncompressed_rle["size"]rle = mask_utils.frPyObjects(uncompressed_rle, h, w)rle["counts"] = rle["counts"].decode("utf-8")# Necessary to serialize with jsonreturn rle
1
6
1
61
1
469
475
469
null
['rle']
None
null
0
0
0
null
0
null
The function (coco_encode_rle) defined within the public class called public.The function start at line 469 and ends at 475. It contains 6 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
batched_mask_to_box
def batched_mask_to_box(masks: torch.Tensor) -> torch.Tensor:"""Calculates boxes in XYXY format around masks. Return [0,0,0,0] foran empty mask. For input shape C1xC2x...xHxW, the output shape is C1xC2x...x4."""# # torch.max below raises an error on empty inputs, just skip in this case# if torch.numel(masks) == 0:# ret...
3
25
1
292
6
480
523
480
null
['out', 'empty_filter', 'shape', 'masks', 'in_height_coords', 'in_width_coords']
None
null
0
0
0
null
0
null
The function (batched_mask_to_box) defined within the public class called public.The function start at line 480 and ends at 523. It contains 25 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_sdpa_settings
def get_sdpa_settings():if torch.cuda.is_available():old_gpu = torch.cuda.get_device_properties(0).major < 7# only use Flash Attention on Ampere (8.0) or newer GPUsuse_flash_attn = torch.cuda.get_device_properties(0).major >= 8if not use_flash_attn:warnings.warn("Flash Attention is disabled as it requires a GPU with Am...
6
24
0
139
4
18
45
18
null
['pytorch_version', 'use_flash_attn', 'math_kernel_on', 'old_gpu']
None
null
0
0
0
null
0
null
The function (get_sdpa_settings) defined within the public class called public.The function start at line 18 and ends at 45. It contains 24 lines of code and it has a cyclomatic complexity of 6. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
get_connected_components
def get_connected_components(mask):"""Get the connected components (8-connectivity) of binary masks of shape (N, 1, H, W).Inputs:- mask: A binary mask tensor of shape (N, 1, H, W), where 1 is foreground and 0 isbackground.Outputs:- labels: A tensor of shape (N, 1, H, W) containing the connected component labelsfor fore...
1
3
1
28
0
48
64
48
null
[]
None
null
0
0
0
null
0
null
The function (get_connected_components) defined within the public class called public.The function start at line 48 and ends at 64. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
mask_to_box
def mask_to_box(masks: torch.Tensor):"""compute bounding box given an input maskInputs:- masks: [B, 1, H, W] masks, dtype=torch.TensorReturns:- box_coords: [B, 1, 4], contains (x, y) coordinates of top left and bottom right box corners, dtype=torch.Tensor"""B, _, h, w = masks.shapedevice = masks.devicexs = torch.arange...
1
14
1
265
6
67
90
67
null
['bbox_coords', 'device', 'grid_xs', 'xs', 'ys', 'grid_ys']
None
null
0
0
0
null
0
null
The function (mask_to_box) defined within the public class called public.The function start at line 67 and ends at 90. It contains 14 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_load_img_as_tensor
def _load_img_as_tensor(img_path, image_size):img_pil = Image.open(img_path)img_np = np.array(img_pil.convert("RGB").resize((image_size, image_size)))if img_np.dtype == np.uint8:# np.uint8 is expected for JPEG imagesimg_np = img_np / 255.0else:raise RuntimeError(f"Unknown image dtype: {img_np.dtype} on {img_path}")img ...
2
10
2
91
3
93
102
93
null
['img_pil', 'img', 'img_np']
None
null
0
0
0
null
0
null
The function (_load_img_as_tensor) defined within the public class called public.The function start at line 93 and ends at 102. It contains 10 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [93.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__._load_frames
def _load_frames():try:for n in tqdm(range(len(self.images)), desc="frame loading (JPEG)"):self.__getitem__(n)except Exception as e:self.exception = e
3
6
0
42
0
138
143
138
null
[]
None
null
0
0
0
null
0
null
The function (__init__._load_frames) defined within the public class called public.The function start at line 138 and ends at 143. It contains 6 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,img_paths,image_size,offload_video_to_cpu,img_mean,img_std,compute_device,):self.img_paths = img_pathsself.image_size = image_sizeself.offload_video_to_cpu = offload_video_to_cpuself.img_mean = img_meanself.img_std = img_std# items in `self.images` will be loaded asynchronouslyself.images = [None] * l...
1
23
7
104
0
110
146
110
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 110 and ends at 146. It contains 23 lines of code and it has a cyclomatic complexity of 1. It takes 7 parameters, represented as [110.0] and does not return any value..
pytorch_ao
public
public
0
0
__getitem__
def __getitem__(self, index):if self.exception is not None:raise RuntimeError("Failure in frame loading thread") from self.exceptionimg = self.images[index]if img is not None:return imgimg, video_height, video_width = _load_img_as_tensor(self.img_paths[index], self.image_size)self.video_height = video_heightself.video_...
4
17
2
110
0
148
167
148
null
[]
None
null
0
0
0
null
0
null
The function (__getitem__) defined within the public class called public.The function start at line 148 and ends at 167. It contains 17 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [148.0] and does not return any value..
pytorch_ao
public
public
0
0
__len__
def __len__(self):return len(self.images)
1
2
1
12
0
169
170
169
null
[]
None
null
0
0
0
null
0
null
The function (__len__) defined within the public class called public.The function start at line 169 and ends at 170. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
load_video_frames
def load_video_frames(video_path,image_size,offload_video_to_cpu,img_mean=(0.485, 0.456, 0.406),img_std=(0.229, 0.224, 0.225),async_loading_frames=False,compute_device=torch.device("cuda"),):"""Load the video frames from video_path. The frames are resized to image_size as inthe model and are loaded to GPU if offload_vi...
6
35
6
178
3
173
211
173
null
['is_mp4_path', 'is_bytes', 'is_str']
None
null
0
0
0
null
0
null
The function (load_video_frames) defined within the public class called public.The function start at line 173 and ends at 211. It contains 35 lines of code and it has a cyclomatic complexity of 6. It takes 6 parameters, represented as [173.0] and does not return any value..
pytorch_ao
public
public
0
0
load_video_frames_from_jpg_images
def load_video_frames_from_jpg_images(video_path,image_size,offload_video_to_cpu,img_mean=(0.485, 0.456, 0.406),img_std=(0.229, 0.224, 0.225),async_loading_frames=False,compute_device=torch.device("cuda"),):"""Load the video frames from a directory of JPEG files ("<frame_index>.jpg" format).The frames are resized to im...
10
53
6
350
8
214
278
214
null
['images', 'img_mean', 'jpg_folder', 'num_frames', 'frame_names', 'img_std', 'img_paths', 'lazy_images']
None
null
0
0
0
null
0
null
The function (load_video_frames_from_jpg_images) defined within the public class called public.The function start at line 214 and ends at 278. It contains 53 lines of code and it has a cyclomatic complexity of 10. It takes 6 parameters, represented as [214.0] and does not return any value..
pytorch_ao
public
public
0
0
load_video_frames_from_video_file
def load_video_frames_from_video_file(video_path,image_size,offload_video_to_cpu,img_mean=(0.485, 0.456, 0.406),img_std=(0.229, 0.224, 0.225),compute_device=torch.device("cuda"),):"""Load the video frames from a video file."""import decordimg_mean = torch.tensor(img_mean, dtype=torch.float32)[:, None, None]img_std = to...
3
24
6
220
3
281
310
281
null
['img_std', 'images', 'img_mean']
None
null
0
0
0
null
0
null
The function (load_video_frames_from_video_file) defined within the public class called public.The function start at line 281 and ends at 310. It contains 24 lines of code and it has a cyclomatic complexity of 3. It takes 6 parameters, represented as [281.0] and does not return any value..
pytorch_ao
public
public
0
0
fill_holes_in_mask_scores
def fill_holes_in_mask_scores(mask, max_area):"""A post processor to fill small holes in mask scores with area under `max_area`."""# Holes are those connected components in background with area <= self.max_area# (background regions are those with mask scores <= 0)assert max_area > 0, "max_area must be positive"input_ma...
2
18
2
85
3
313
339
313
null
['is_hole', 'input_mask', 'mask']
None
null
0
0
0
null
0
null
The function (fill_holes_in_mask_scores) defined within the public class called public.The function start at line 313 and ends at 339. It contains 18 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [313.0] and does not return any value..
pytorch_ao
public
public
0
0
concat_points
def concat_points(old_point_inputs, new_points, new_labels):"""Add new points and labels to previous point inputs (add at the end)."""if old_point_inputs is None:points, labels = new_points, new_labelselse:points = torch.cat([old_point_inputs["point_coords"], new_points], dim=1)labels = torch.cat([old_point_inputs["poi...
2
7
3
72
2
342
350
342
null
['labels', 'points']
None
null
0
0
0
null
0
null
The function (concat_points) defined within the public class called public.The function start at line 342 and ends at 350. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [342.0] and does not return any value..
pytorch_ao
public
public
0
0
get_image_size
def get_image_size(image: Union[np.ndarray, torch.Tensor]):if isinstance(image, np.ndarray):return image.shape[:2]elif isinstance(image, torch.Tensor):_, h, w = image.shapereturn (h, w)elif isinstance(image, Image):w, h = image.sizereturn (h, w)else:raise NotImplementedError(f"Only support np.ndarray, torch.Tensoror PI...
4
13
1
88
0
353
365
353
null
[]
None
null
0
0
0
null
0
null
The function (get_image_size) defined within the public class called public.The function start at line 353 and ends at 365. It contains 13 lines of code and it has a cyclomatic complexity of 4. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
crop_image
def crop_image(image: Union[np.ndarray, torch.Tensor], crop_box: Tuple[int, int, int, int]):x0, y0, x1, y1 = crop_boxif isinstance(image, np.ndarray):# HxWxCreturn image[y0:y1, x0:x1, :]elif isinstance(image, torch.Tensor):# CxHxWreturn image[:, y0:y1, x0:x1]else:raise ValueError("Expected image to be of type np.ndarra...
3
13
2
93
0
368
382
368
null
[]
None
null
0
0
0
null
0
null
The function (crop_image) defined within the public class called public.The function start at line 368 and ends at 382. It contains 13 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [368.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self, resolution, mask_threshold, max_hole_area=0.0, max_sprinkle_area=0.0):"""Transforms for SAM2."""super().__init__()self.resolution = resolutionself.mask_threshold = mask_thresholdself.max_hole_area = max_hole_areaself.max_sprinkle_area = max_sprinkle_areaself.mean = [0.485, 0.456, 0.406]self.std = [0....
1
15
5
123
0
16
34
16
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 16 and ends at 34. It contains 15 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [16.0] and does not return any value..
pytorch_ao
public
public
0
0
__call__
def __call__(self, x):x = self.to_tensor(x)return self.transforms(x)
1
3
2
22
0
36
38
36
null
[]
None
null
0
0
0
null
0
null
The function (__call__) defined within the public class called public.The function start at line 36 and ends at 38. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [36.0] and does not return any value..
pytorch_ao
public
public
0
0
forward_batch
def forward_batch(self, img_list):img_batch = [self.transforms(self.to_tensor(img)) for img in img_list]img_batch = torch.stack(img_batch, dim=0)return img_batch
2
4
2
40
0
40
43
40
null
[]
None
null
0
0
0
null
0
null
The function (forward_batch) defined within the public class called public.The function start at line 40 and ends at 43. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [40.0] and does not return any value..
pytorch_ao
public
public
0
0
transform_coords
def transform_coords(self, coords: torch.Tensor, normalize=False, orig_hw=None) -> torch.Tensor:"""Expects a torch tensor with length 2 in the last dimension. The coordinates can be in absolute image or normalized coordinates,If the coords are in absolute image coordinates, normalize should be set to True and original ...
2
11
4
83
0
45
63
45
null
[]
None
null
0
0
0
null
0
null
The function (transform_coords) defined within the public class called public.The function start at line 45 and ends at 63. It contains 11 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [45.0] and does not return any value..
pytorch_ao
public
public
0
0
transform_boxes
def transform_boxes(self, boxes: torch.Tensor, normalize=False, orig_hw=None) -> torch.Tensor:"""Expects a tensor of shape Bx4. The coordinates can be in absolute image or normalized coordinates,if the coords are in absolute image coordinates, normalize should be set to True and original image size is required."""boxes...
1
5
4
48
0
65
73
65
null
[]
None
null
0
0
0
null
0
null
The function (transform_boxes) defined within the public class called public.The function start at line 65 and ends at 73. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [65.0] and does not return any value..
pytorch_ao
public
public
0
0
postprocess_masks
def postprocess_masks(self, masks: torch.Tensor, orig_hw, output_dtype) -> torch.Tensor:"""Perform PostProcessing on output masks."""from torchao._models.sam2.utils.misc import get_connected_componentsmasks = masks.float()input_masks = masksmask_flat = masks.flatten(0, 1).unsqueeze(1)# flatten as 1-channel imagetry:if ...
4
35
4
234
0
75
120
75
null
[]
None
null
0
0
0
null
0
null
The function (postprocess_masks) defined within the public class called public.The function start at line 75 and ends at 120. It contains 35 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [75.0] and does not return any value..
pytorch_ao
public
public
0
0
postprocess_masks_1_channel
def postprocess_masks_1_channel(self, masks: torch.Tensor, orig_hw, output_dtype) -> torch.Tensor:"""Perform PostProcessing on output masks."""from torchao._models.sam2.utils.misc import get_connected_componentsassert masks.dim() == 4assert masks.size(1) == 1masks = masks.float()input_masks = masks# mask_flat = masks.f...
4
35
4
223
0
122
170
122
null
[]
None
null
0
0
0
null
0
null
The function (postprocess_masks_1_channel) defined within the public class called public.The function start at line 122 and ends at 170. It contains 35 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [122.0] and does not return any value..
pytorch_ao
public
public
0
0
default
def default(self, o):# Handle AOBaseConfig subclasses first (most specific case)if isinstance(o, AOBaseConfig):data_dict = {}# Process each attribute to handle nested objectsfor k, v in o.__dict__.items():if not k.startswith("_") and k != "version":# Recursively encode each value (important for nested objects)data_dict...
26
56
2
467
0
73
156
73
null
[]
None
null
0
0
0
null
0
null
The function (default) defined within the public class called public.The function start at line 73 and ends at 156. It contains 56 lines of code and it has a cyclomatic complexity of 26. It takes 2 parameters, represented as [73.0] and does not return any value..
pytorch_ao
public
public
0
0
encode_value
def encode_value(self, value):"""Helper method to recursively encode a value"""# Try to use default for custom typetry:# This will handle all our special cases and raise TypeError# if it can't handle the typeresult = self.default(value)return resultexcept TypeError:pass# Default case - return as is# (This will be proce...
2
7
2
26
0
158
171
158
null
[]
None
null
0
0
0
null
0
null
The function (encode_value) defined within the public class called public.The function start at line 158 and ends at 171. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [158.0] and does not return any value..
pytorch_ao
public
public
0
0
config_to_dict
def config_to_dict(config: AOBaseConfig) -> Dict[str, Any]:"""Convert an AOBaseConfig instance to a dictionary suitable for serialization.Args:config: An instance of AOBaseConfig subclassReturns:Dict representation of the config"""if not isinstance(config, AOBaseConfig):raise TypeError(f"Expected AOBaseConfig instance,...
2
4
1
46
0
174
188
174
null
[]
None
null
0
0
0
null
0
null
The function (config_to_dict) defined within the public class called public.The function start at line 174 and ends at 188. It contains 4 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
config_from_dict
def config_from_dict(data: Dict[str, Any]) -> AOBaseConfig:"""Create an AOBaseConfig subclass instance from a dictionary.Args:data: Dictionary containing serialized config dataReturns:An instance of the appropriate AOBaseConfig subclassRaises:ValueError: If deserialization fails for other reasons"""if not isinstance(da...
29
69
1
381
8
205
306
205
null
['obj_data', 'cls', 'allowed_modules_str', 'current_default_version', 'stored_version', 'processed_data', 'module', 'type_path']
None
null
0
0
0
null
0
null
The function (config_from_dict) defined within the public class called public.The function start at line 205 and ends at 306. It contains 69 lines of code and it has a cyclomatic complexity of 29. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
add_test_string
def add_test_string(kernel, m, n, k, g, has_bias, has_clamp):name = f"m{m}xn{n}xk{k}xg{g}{'_bias' if has_bias else ''}{'_clamp' if has_clamp else ''}"d = {"name": name,"kernel": kernel,"m": m,"n": n,"k": k,"g": g,"has_bias": "true" if has_bias else "false","has_clamp": "true" if has_clamp else "false",}test_template = ...
3
27
7
80
3
8
36
8
null
['test_template', 'name', 'd']
None
null
0
0
0
null
0
null
The function (add_test_string) defined within the public class called public.The function start at line 8 and ends at 36. It contains 27 lines of code and it has a cyclomatic complexity of 3. It takes 7 parameters, represented as [8.0] and does not return any value..
pytorch_ao
public
public
0
0
get_test_block
def get_test_block(kernel):# Assuming given kleidi kernel can run with all these test casestests = []# GEMV, m == 1## subtiletests += add_test_string(kernel, 1, 2 * 1, 32, 32, False, False)tests += add_test_string(kernel, 1, 2 * 2, 32, 32, False, False)tests += add_test_string(kernel, 1, 2 * 3, 32, 32, True, False)test...
1
42
1
780
1
39
94
39
null
['tests']
None
null
0
0
0
null
0
null
The function (get_test_block) defined within the public class called public.The function start at line 39 and ends at 94. It contains 42 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
main
def main():kleidi_template = Template("""/*****************/// ${kernel} tests /*****************/${prologue}${tests}${epilogue}""")kleidi_kernels = ["dotprod_1x4x32","dotprod_1x8x32","i8mm_4x8x32","i8mm_8x4x32",]print("/* Generated by generate_tests.py */")print("/* Do not modify */")print()print("#if defined(TORCHAO_...
3
35
0
99
6
97
134
97
null
['epilogue', 'prologue', 'kleidi_kernels', 'kleidi_template', 'tests', 'd']
None
null
0
0
0
null
0
null
The function (main) defined within the public class called public.The function start at line 97 and ends at 134. It contains 35 lines of code and it has a cyclomatic complexity of 3. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_nf4_weight_only_transform
def _nf4_weight_only_transform(module: torch.nn.Module,config: NF4WeightOnlyConfig,) -> torch.nn.Module:block_size = config.block_sizescaler_block_size = config.scaler_block_sizenew_weight = NF4Tensor.from_tensor(module.weight, block_size, scaler_block_size)module.weight = torch.nn.Parameter(new_weight, requires_grad=F...
1
9
2
64
3
30
39
30
null
['scaler_block_size', 'new_weight', 'block_size']
None
null
0
0
0
null
0
null
The function (_nf4_weight_only_transform) defined within the public class called public.The function start at line 30 and ends at 39. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [30.0] and does not return any value..
pytorch_ao
public
public
0
0
__new__
def __new__(cls,tensor_impl: AQTTensorImpl,block_size: Tuple[int, ...],shape: torch.Size,quant_min: Optional[Union[int, float]] = None,quant_max: Optional[Union[int, float]] = None,zero_point_domain: ZeroPointDomain = ZeroPointDomain.INT,dtype=None,strides=None,):if zero_point_domain is None:raise ValueError("please us...
4
23
9
155
0
84
106
84
null
[]
None
null
0
0
0
null
0
null
The function (__new__) defined within the public class called public.The function start at line 84 and ends at 106. It contains 23 lines of code and it has a cyclomatic complexity of 4. It takes 9 parameters, represented as [84.0] and does not return any value..
pytorch_ao
public
public
0
0
__init__
def __init__(self,tensor_impl: AQTTensorImpl,block_size: Tuple[int, ...],shape: torch.Size,quant_min: Optional[Union[int, float]] = None,quant_max: Optional[Union[int, float]] = None,zero_point_domain: ZeroPointDomain = ZeroPointDomain.INT,dtype=None,strides=None,):torch._C._log_api_usage_once(str(type(self)))self.tens...
1
17
9
108
0
108
124
108
null
[]
None
null
0
0
0
null
0
null
The function (__init__) defined within the public class called public.The function start at line 108 and ends at 124. It contains 17 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [108.0] and does not return any value..
pytorch_ao
public
public
0
0
__repr__
def __repr__(self):return (f"{self.__class__.__name__}(tensor_impl={self.tensor_impl}, block_size={self.block_size}, "f"shape={self.shape}, device={self.device}, dtype={self.dtype}, requires_grad={self.requires_grad})")
1
5
1
12
0
126
130
126
null
[]
None
null
0
0
0
null
0
null
The function (__repr__) defined within the public class called public.The function start at line 126 and ends at 130. It contains 5 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_quantization_type
def _quantization_type(self):return f"shape={self.shape}, block_size={self.block_size}, device={self.device}, _layout={self._layout}, tensor_impl_dtype={self.tensor_impl.dtype}, quant_min={self.quant_min}, quant_max={self.quant_max}"
1
2
1
8
0
132
133
132
null
[]
None
null
0
0
0
null
0
null
The function (_quantization_type) defined within the public class called public.The function start at line 132 and ends at 133. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
dequantize
def dequantize(self, output_dtype: Optional[torch.dtype] = None) -> torch.Tensor:if output_dtype is None:output_dtype = self.dtypefrom torchao.dtypes.floatx import Float8Layout, FloatxTensorCoreLayoutif isinstance(self._layout, FloatxTensorCoreLayout):int_data, scale = self.tensor_impl.get_plain()return _dequantize_aff...
8
56
2
289
0
135
197
135
null
[]
None
null
0
0
0
null
0
null
The function (dequantize) defined within the public class called public.The function start at line 135 and ends at 197. It contains 56 lines of code and it has a cyclomatic complexity of 8. It takes 2 parameters, represented as [135.0] and does not return any value..
pytorch_ao
public
public
0
0
__tensor_flatten__
def __tensor_flatten__(self):# This is used in rumtime to unwrap AffineQuantizedTensor activations.# AffineQuantizedTensor has __torch_function__ override:# Each getattr will go through it, which is up to 10x slower than default attribute access.with torch._C.DisableTorchFunctionSubclass():return ["tensor_impl"], [self...
1
10
1
45
0
199
211
199
null
[]
None
null
0
0
0
null
0
null
The function (__tensor_flatten__) defined within the public class called public.The function start at line 199 and ends at 211. It contains 10 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
__tensor_unflatten__
def __tensor_unflatten__(cls, tensor_data_dict, tensor_attributes, outer_size, outer_stride):tensor_impl = tensor_data_dict["tensor_impl"]block_size, shape, quant_min, quant_max, zero_point_domain, dtype = (tensor_attributes)return cls(tensor_impl,block_size,shape if outer_size is None else outer_size,quant_min,quant_m...
2
17
5
64
0
214
230
214
null
[]
None
null
0
0
0
null
0
null
The function (__tensor_unflatten__) defined within the public class called public.The function start at line 214 and ends at 230. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [214.0] and does not return any value..
pytorch_ao
public
public
0
0
from_hp_to_intx
def from_hp_to_intx(cls,input_float: torch.Tensor,mapping_type: MappingType,block_size: Tuple[int, ...],target_dtype: torch.dtype,quant_min: Optional[int] = None,quant_max: Optional[int] = None,eps: Optional[float] = None,scale_dtype: Optional[torch.dtype] = None,zero_point_dtype: Optional[torch.dtype] = None,preserve_...
15
139
13
566
0
233
383
233
null
[]
None
null
0
0
0
null
0
null
The function (from_hp_to_intx) defined within the public class called public.The function start at line 233 and ends at 383. It contains 139 lines of code and it has a cyclomatic complexity of 15. It takes 13 parameters, represented as [233.0] and does not return any value..
pytorch_ao
public
public
0
0
from_hp_to_intx_static
def from_hp_to_intx_static(cls,input_float: torch.Tensor,scale: torch.Tensor,zero_point: Optional[torch.Tensor],block_size: Tuple[int, ...],target_dtype: torch.dtype,quant_min: Optional[int] = None,quant_max: Optional[int] = None,zero_point_domain: ZeroPointDomain = ZeroPointDomain.INT,_layout: Layout = PlainLayout(),)...
6
68
10
265
0
386
457
386
null
[]
None
null
0
0
0
null
0
null
The function (from_hp_to_intx_static) defined within the public class called public.The function start at line 386 and ends at 457. It contains 68 lines of code and it has a cyclomatic complexity of 6. It takes 10 parameters, represented as [386.0] and does not return any value..
pytorch_ao
public
public
0
0
from_hp_to_floatx
def from_hp_to_floatx(cls,input_float: torch.Tensor,block_size: Tuple[int, ...],target_dtype: torch.dtype,_layout: Layout,scale_dtype: Optional[torch.dtype] = None,):"""Convert a high precision tensor to a float8 quantized tensor."""if target_dtype in FP8_TYPES:original_shape = input_float.shapeinput_float = _layout.pr...
2
30
6
148
0
460
490
460
null
[]
None
null
0
0
0
null
0
null
The function (from_hp_to_floatx) defined within the public class called public.The function start at line 460 and ends at 490. It contains 30 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [460.0] and does not return any value..
pytorch_ao
public
public
0
0
from_hp_to_floatx_static
def from_hp_to_floatx_static(cls,input_float: torch.Tensor,scale: torch.Tensor,block_size: Tuple[int, ...],target_dtype: torch.dtype,_layout: Layout,scale_dtype: torch.dtype = torch.float32,):"""Create a float8 AffineQuantizedTensor from a high precision tensor using static parameters."""if target_dtype in FP8_TYPES:or...
2
37
7
153
0
493
533
493
null
[]
None
null
0
0
0
null
0
null
The function (from_hp_to_floatx_static) defined within the public class called public.The function start at line 493 and ends at 533. It contains 37 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [493.0] and does not return any value..
pytorch_ao
public
public
0
0
from_hp_to_fpx
def from_hp_to_fpx(cls,input_float: torch.Tensor,_layout: Layout,):"""Create a floatx AffineQuantizedTensor from a high precision tensor. Floatx is represented as ebits and mbits, and supports the representation of float1-float7."""from torchao.dtypes.floatx import FloatxTensorCoreLayoutassert isinstance(_layout, Float...
1
22
3
151
0
536
563
536
null
[]
None
null
0
0
0
null
0
null
The function (from_hp_to_fpx) defined within the public class called public.The function start at line 536 and ends at 563. It contains 22 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [536.0] and does not return any value..
pytorch_ao
public
public
0
0
_layout
def _layout(self) -> Layout:return self.tensor_impl._layout
1
2
1
13
0
566
567
566
null
[]
None
null
0
0
0
null
0
null
The function (_layout) defined within the public class called public.The function start at line 566 and ends at 567. It contains 2 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
to
def to(self, *args, **kwargs):kwargs = self._get_to_kwargs(*args, **kwargs)device = kwargs.pop("device")return self.__class__(self.tensor_impl.to(device),self.block_size,self.shape,self.quant_min,self.quant_max,self.zero_point_domain,**kwargs,)
1
12
3
69
0
569
580
569
null
[]
None
null
0
0
0
null
0
null
The function (to) defined within the public class called public.The function start at line 569 and ends at 580. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [569.0] and does not return any value..
pytorch_ao
public
public
0
0
_apply_fn_to_data
def _apply_fn_to_data(self, fn):return self.__class__(fn(self.tensor_impl),self.block_size,self.shape,self.quant_min,self.quant_max,self.zero_point_domain,dtype=self.dtype,strides=self.stride(),)
1
11
2
54
0
582
592
582
null
[]
None
null
0
0
0
null
0
null
The function (_apply_fn_to_data) defined within the public class called public.The function start at line 582 and ends at 592. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [582.0] and does not return any value..
pytorch_ao
public
public
0
0
register_aqt_quantized_linear_dispatch
def register_aqt_quantized_linear_dispatch(dispatch_condition, impl):"""Register a dispatch for quantized linear op with dispatch_condition function and impl functionboth takes three arguments:input_tensor: dimension is (M1, M2, ..., in_features)weight_tensor: dimension is (out_features, in_features)bias: dimension is ...
1
2
2
14
0
116
130
116
null
[]
None
null
0
0
0
null
0
null
The function (register_aqt_quantized_linear_dispatch) defined within the public class called public.The function start at line 116 and ends at 130. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [116.0] and does not return any value..
pytorch_ao
public
public
0
0
deregister_aqt_quantized_linear_dispatch
def deregister_aqt_quantized_linear_dispatch(dispatch_condition):if dispatch_condition in _AQT_QLINEAR_DISPATCH_TABLE:del _AQT_QLINEAR_DISPATCH_TABLE[dispatch_condition]else:logger.warning(f"Attempting to remove non-existent dispatch condition {dispatch_condition}")
2
7
1
24
0
133
139
133
null
[]
None
null
0
0
0
null
0
null
The function (deregister_aqt_quantized_linear_dispatch) defined within the public class called public.The function start at line 133 and ends at 139. It contains 7 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_same_metadata
def _same_metadata(self: AffineQuantizedTensor, src: AffineQuantizedTensor):return (isinstance(self, AffineQuantizedTensor)and isinstance(src, AffineQuantizedTensor)and all([getattr(self, attr) == getattr(src, attr)for attr in ["block_size","shape","quant_min","quant_max","zero_point_domain","dtype",]])and isinstance(s...
5
19
2
77
0
142
160
142
null
[]
None
null
0
0
0
null
0
null
The function (_same_metadata) defined within the public class called public.The function start at line 142 and ends at 160. It contains 19 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [142.0] and does not return any value..
pytorch_ao
public
public
0
0
_quantized_linear_op
def _quantized_linear_op(input_tensor, weight_tensor, bias):for dispatch_condition, impl in _AQT_QLINEAR_DISPATCH_TABLE.items():if dispatch_condition(input_tensor, weight_tensor, bias):return impl(input_tensor, weight_tensor, bias)raise QuantizedLinearNotImplementedError("No specialized dispatch found for quantized lin...
3
7
3
44
0
173
179
173
null
[]
None
null
0
0
0
null
0
null
The function (_quantized_linear_op) defined within the public class called public.The function start at line 173 and ends at 179. It contains 7 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [173.0] and does not return any value..
pytorch_ao
public
public
0
0
_register_aqt_quantized_linear_dispatches
def _register_aqt_quantized_linear_dispatches():for dispatch_condition, impl in [(_linear_int8_act_int8_weight_check, _linear_int8_act_int8_weight_impl),(_linear_int8_act_int8_weight_semi_structured_sparse_check,_linear_int8_act_int8_weight_semi_structured_sparse_impl,),(_linear_int8_act_int8_weight_block_sparse_check,...
2
69
0
153
0
191
259
191
null
[]
None
null
0
0
0
null
0
null
The function (_register_aqt_quantized_linear_dispatches) defined within the public class called public.The function start at line 191 and ends at 259. It contains 69 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):input_tensor, weight_tensor, bias = (args[0],args[1],args[2] if len(args) > 2 else None,)if not input_tensor.is_floating_point():raise NotImplementedError(f"{func} is not implemented for non floating point input")# using try/except here so that we can have a general fallback when input_...
9
24
4
150
2
268
296
268
null
['weight_tensor', 'input_tensor']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 268 and ends at 296. It contains 24 lines of code and it has a cyclomatic complexity of 9. It takes 4 parameters, represented as [268.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):if _embedding_q_dq_check(args, kwargs):return _embedding_q_dq_impl(args, kwargs)# new_arg1 = args[1].dequantize()# return torch.nn.embedding(args[0], new_arg1, *args[2:], **kwargs)assert isinstance(args[1].tensor_impl, PlainAQTTensorImpl), (f"embedding only works with PlainAQTTensorImpl...
8
37
4
219
3
300
344
300
null
['idx', 'new_blocks', '_dequantize_affine']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 300 and ends at 344. It contains 37 lines of code and it has a cyclomatic complexity of 8. It takes 4 parameters, represented as [300.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):input_tensor, weight_tensor, bias = (args[1],args[2],args[0],)if not input_tensor.is_floating_point():raise NotImplementedError(f"{func} is not implemented for non floating point input")assert input_tensor.shape[-1] == weight_tensor.shape[0], (f"need mat1 shape: {input_tensor.shape} fin...
8
31
4
164
3
348
385
348
null
['weight_tensor', 'input_tensor', 'transposed_weight_tensor']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 348 and ends at 385. It contains 31 lines of code and it has a cyclomatic complexity of 8. It takes 4 parameters, represented as [348.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):input_tensor, weight_tensor, bias = (args[0], args[1], None)if not input_tensor.is_floating_point():raise NotImplementedError(f"{func} is not implemented for non floating point input")assert input_tensor.shape[-1] == weight_tensor.shape[0], (f"need mat1 shape: {input_tensor.shape} final...
8
27
4
158
3
389
419
389
null
['weight_tensor', 'input_tensor', 'transposed_weight_tensor']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 389 and ends at 419. It contains 27 lines of code and it has a cyclomatic complexity of 8. It takes 4 parameters, represented as [389.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.detach))
1
4
4
32
0
423
426
423
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 423 and ends at 426. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [423.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.detach))
1
4
4
32
0
430
433
423
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 430 and ends at 433. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [423.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func, args, kwargs, args[0]._apply_fn_to_data(torch.detach))
1
4
4
32
0
437
440
423
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 437 and ends at 440. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [423.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):return return_and_correct_aliasing(func,args,kwargs,args[0].to(*args[1:], **kwargs)._apply_fn_to_data(torch.clone),)
1
7
4
46
0
444
450
444
null
[]
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 444 and ends at 450. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [444.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):self = args[0]src = args[1]if _same_metadata(self, src):self_tensors = self.__tensor_flatten__()[0]for tensor_name in self_tensors:getattr(self, tensor_name).copy_(getattr(src, tensor_name))returnraise ValueError(f"Not supported args for copy_ due to metadata mistach: {args[0], args[1]}...
3
11
4
69
3
454
464
454
null
['self_tensors', 'src', 'self']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 454 and ends at 464. It contains 11 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [454.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):block_size = args[0].block_sizeassert len(block_size) == 2transposed_block_size = (block_size[1], block_size[0])tensor = args[0]shape = tensor.shape[::-1]new = tensor.__class__(tensor.tensor_impl.t(),transposed_block_size,shape,tensor.quant_min,tensor.quant_max,tensor.zero_point_domain,...
1
17
4
111
5
468
484
468
null
['shape', 'tensor', 'block_size', 'new', 'transposed_block_size']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 468 and ends at 484. It contains 17 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [468.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):if _embedding_q_dq_check(args, kwargs):return _embedding_q_dq_impl(args, kwargs)# new_arg1 = args[1].dequantize()# return torch.nn.embedding(args[0], new_arg1, *args[2:], **kwargs)assert isinstance(args[1].tensor_impl, PlainAQTTensorImpl), (f"embedding only works with PlainAQTTensorImpl...
5
26
4
219
3
488
516
300
null
['idx', 'new_blocks', '_dequantize_affine']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 488 and ends at 516. It contains 26 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [300.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):self, indices = argsassert len(indices) == 1, (f"op {func} currently only implemented for single dimensional indexing but got indices: {indices}")new_tensor_impl = aten.index.Tensor(self.tensor_impl, indices)shape = tuple([indices[0].numel(), *self.shape[1:]])block_size = self.block_siz...
1
18
4
113
4
520
538
520
null
['new_tensor_impl', 'shape', 'block_size', 'new']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 520 and ends at 538. It contains 18 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [520.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):self, dim, index = fill_defaults(args, 3, [0, 0])assert dim == 0, f"op {func} currently only implemented for dim=0 but got dim={dim}"assert self.dim() == 3, (f"op {func} currently only implemented for 3 dimensional tensors but got shape={self.shape}")new_tensor_impl = aten.select.int(se...
1
19
4
125
4
542
562
542
null
['new_tensor_impl', 'shape', 'block_size', 'new']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 542 and ends at 562. It contains 19 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [542.0] and does not return any value..
pytorch_ao
public
public
0
0
_
def _(func, types, args, kwargs):self, shape = argsif tuple(self.shape) == tuple(shape):return self.__class__(self.tensor_impl,self.block_size,self.shape,self.quant_min,self.quant_max,self.zero_point_domain,dtype=self.dtype,strides=self.stride(),)if len(shape) == 1 and shape[0] == -1:assert len(self.block_size) == 2 an...
5
29
4
171
1
567
598
567
null
['block_size']
None
null
0
0
0
null
0
null
The function (_) defined within the public class called public.The function start at line 567 and ends at 598. It contains 29 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [567.0] and does not return any value..
pytorch_ao
public
public
0
0
nf4_all_gather_into_tensor
def nf4_all_gather_into_tensor(func, *args, **kwargs):assert len(args) > 1, "Expected valid input"assert len(args[0]) == 3, "Expected 3 input args"nf4tensor = args[0][0]group_size = args[0][1]name = args[0][2]updated_attrs = {}for attr in _INNER_TENSOR_NAMES_FOR_SHARDING:updated_attrs[attr] = func(getattr(nf4tensor, at...
2
16
3
136
5
23
38
23
null
['updated_attrs', 'group_size', 'nf4tensor', 'updatedNF4Tensor', 'name']
None
null
0
0
0
null
0
null
The function (nf4_all_gather_into_tensor) defined within the public class called public.The function start at line 23 and ends at 38. It contains 16 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [23.0] and does not return any value..
pytorch_ao
public
public
0
0
scatter_nf4tensor
def scatter_nf4tensor(func, *args, **kwargs):assert len(args) > 1, "Expected valid input"assert len(args[0][0]) == 1, "Expected 1 output tensor"output_tensor = args[0][0][0]input_tensors = args[0][1]new_attr, update_work = [], []for attr in _INNER_TENSOR_NAMES_FOR_SHARDING:input_attrs = []if input_tensors:for input_ten...
5
20
3
156
3
41
61
41
null
['input_attrs', 'output_tensor', 'input_tensors']
None
null
0
0
0
null
0
null
The function (scatter_nf4tensor) defined within the public class called public.The function start at line 41 and ends at 61. It contains 20 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [41.0] and does not return any value..
pytorch_ao
public
public
0
0
same_metadata
def same_metadata(a: "NF4Tensor", b: "NF4Tensor"):both_nf4 = isinstance(a, NF4Tensor) and isinstance(b, NF4Tensor)return (both_nf4and a.block_size == b.block_sizeand a.scaler_block_size == b.scaler_block_sizeand a.n_blocks == b.n_blocks)
5
8
2
54
1
85
92
85
null
['both_nf4']
None
null
0
0
0
null
0
null
The function (same_metadata) defined within the public class called public.The function start at line 85 and ends at 92. It contains 8 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [85.0] and does not return any value..
pytorch_ao
public
public
0
0
implements.decorator
def decorator(func):for op in aten_ops:NF4_OPS_TABLE[op] = funcreturn func
2
4
1
18
0
98
101
98
null
[]
None
null
0
0
0
null
0
null
The function (implements.decorator) defined within the public class called public.The function start at line 98 and ends at 101. It contains 4 lines of code and it has a cyclomatic complexity of 2. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
implements
def implements(aten_ops):"""Use this decorator to implement a function for an aten op in __torch_dispatch__"""def decorator(func):for op in aten_ops:NF4_OPS_TABLE[op] = funcreturn funcreturn decorator
1
3
1
10
0
95
103
95
null
[]
None
null
0
0
0
null
0
null
The function (implements) defined within the public class called public.The function start at line 95 and ends at 103. It contains 3 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
construct_nf4_args
def construct_nf4_args(nf4tensor: "NF4Tensor", kwargs: Optional[Dict[str, Any]] = None):if kwargs is None:kwargs = {}tensor_meta = SubclassTensorArgs(kwargs.get("size", nf4tensor.size()),kwargs.get("stride", nf4tensor.stride()),kwargs.get("storage_offset", nf4tensor.storage_offset()),kwargs.get("dtype", nf4tensor.dtype...
2
22
2
200
2
106
127
106
null
['kwargs', 'tensor_meta']
None
null
0
0
0
null
0
null
The function (construct_nf4_args) defined within the public class called public.The function start at line 106 and ends at 127. It contains 22 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [106.0] and does not return any value..
pytorch_ao
public
public
0
0
apply_to_inner_tensors
def apply_to_inner_tensors(nf4tensor: "NF4Tensor", aten_op, args, kwargs):attr_to_tensor = {}for attr in _INNER_TENSOR_NAMES_FOR_SHARDING:attr_to_tensor[attr] = aten_op(getattr(nf4tensor, attr), *args, **kwargs)return attr_to_tensor
2
5
4
44
1
131
135
131
null
['attr_to_tensor']
None
null
0
0
0
null
0
null
The function (apply_to_inner_tensors) defined within the public class called public.The function start at line 131 and ends at 135. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [131.0] and does not return any value..
pytorch_ao
public
public
0
0
call_from_inner_tensors
def call_from_inner_tensors(nf4tensor: "NF4Tensor", method_name: str, args, kwargs):attr_to_tensor = {}for attr in _INNER_TENSOR_NAMES_FOR_SHARDING:inner_tensor = getattr(nf4tensor, attr)func = getattr(inner_tensor, method_name)attr_to_tensor[attr] = func(*args, **kwargs)return attr_to_tensor
2
7
4
55
3
139
145
139
null
['func', 'attr_to_tensor', 'inner_tensor']
None
null
0
0
0
null
0
null
The function (call_from_inner_tensors) defined within the public class called public.The function start at line 139 and ends at 145. It contains 7 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [139.0] and does not return any value..
pytorch_ao
public
public
0
0
expect_num_of_args.expect_num_of_args.decorator.wrapper
def wrapper(aten_op, args, kwargs=None):if op == CompareOp.LT and not (len(args) < num):raise NotImplementedError(msg)return func(aten_op, args, kwargs)
3
4
3
42
0
156
159
156
null
[]
None
null
0
0
0
null
0
null
The function (expect_num_of_args.expect_num_of_args.decorator.wrapper) defined within the public class called public.The function start at line 156 and ends at 159. It contains 4 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [156.0] and does not return any value..
pytorch_ao
public
public
0
0
expect_num_of_args.decorator
def decorator(func):@functools.wraps(func)def wrapper(aten_op, args, kwargs=None):if op == CompareOp.LT and not (len(args) < num):raise NotImplementedError(msg)return func(aten_op, args, kwargs)return wrapper
1
4
1
16
0
154
161
154
null
[]
None
null
0
0
0
null
0
null
The function (expect_num_of_args.decorator) defined within the public class called public.The function start at line 154 and ends at 161. It contains 4 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
expect_num_of_args
def expect_num_of_args(op: CompareOp, num: int, msg: str):def decorator(func):@functools.wraps(func)def wrapper(aten_op, args, kwargs=None):if op == CompareOp.LT and not (len(args) < num):raise NotImplementedError(msg)return func(aten_op, args, kwargs)return wrapperreturn decorator
1
3
3
19
0
153
163
153
null
[]
None
null
0
0
0
null
0
null
The function (expect_num_of_args) defined within the public class called public.The function start at line 153 and ends at 163. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [153.0] and does not return any value..
pytorch_ao
public
public
0
0
expect_arg_value_at_k.expect_arg_value_at_k.decorator.wrapper
def wrapper(aten_op, args, kwargs=None):if op == CompareOp.EQ and not (args[k] == value):raise NotImplementedError(msg + str(args[k]))return func(aten_op, args, kwargs)
3
4
3
50
0
169
172
169
null
[]
None
null
0
0
0
null
0
null
The function (expect_arg_value_at_k.expect_arg_value_at_k.decorator.wrapper) defined within the public class called public.The function start at line 169 and ends at 172. It contains 4 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [169.0] and does not return any value..
pytorch_ao
public
public
0
0
expect_arg_value_at_k.decorator
def decorator(func):@functools.wraps(func)def wrapper(aten_op, args, kwargs=None):if op == CompareOp.EQ and not (args[k] == value):raise NotImplementedError(msg + str(args[k]))return func(aten_op, args, kwargs)return wrapper
1
4
1
16
0
167
174
167
null
[]
None
null
0
0
0
null
0
null
The function (expect_arg_value_at_k.decorator) defined within the public class called public.The function start at line 167 and ends at 174. It contains 4 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
expect_arg_value_at_k
def expect_arg_value_at_k(k: int, op: CompareOp, value: Any, msg: str):def decorator(func):@functools.wraps(func)def wrapper(aten_op, args, kwargs=None):if op == CompareOp.EQ and not (args[k] == value):raise NotImplementedError(msg + str(args[k]))return func(aten_op, args, kwargs)return wrapperreturn decorator
1
3
4
23
0
166
176
166
null
[]
None
null
0
0
0
null
0
null
The function (expect_arg_value_at_k) defined within the public class called public.The function start at line 166 and ends at 176. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [166.0] and does not return any value..
pytorch_ao
public
public
0
0
expect_args_len_at_k.expect_args_len_at_k.decorator.wrapper
def wrapper(aten_op, args, kwargs=None):if op == CompareOp.LT and not (len(args[k]) < value):raise NotImplementedError(msg + str(len(args[k])))elif op == CompareOp.EQ and not (len(args[k]) == value):raise NotImplementedError(msg + str(len(args[k])))return func(aten_op, args, kwargs)
5
6
3
92
0
182
187
182
null
[]
None
null
0
0
0
null
0
null
The function (expect_args_len_at_k.expect_args_len_at_k.decorator.wrapper) defined within the public class called public.The function start at line 182 and ends at 187. It contains 6 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [182.0] and does not return any value..
pytorch_ao
public
public
0
0
expect_args_len_at_k.decorator
def decorator(func):@functools.wraps(func)def wrapper(aten_op, args, kwargs=None):if op == CompareOp.LT and not (len(args[k]) < value):raise NotImplementedError(msg + str(len(args[k])))elif op == CompareOp.EQ and not (len(args[k]) == value):raise NotImplementedError(msg + str(len(args[k])))return func(aten_op, args, kw...
1
4
1
16
0
180
189
180
null
[]
None
null
0
0
0
null
0
null
The function (expect_args_len_at_k.decorator) defined within the public class called public.The function start at line 180 and ends at 189. It contains 4 lines of code and it has a cyclomatic complexity of 1. The function does not take any parameters and does not return any value..
pytorch_ao
public
public
0
0
expect_args_len_at_k
def expect_args_len_at_k(k: int, op: CompareOp, value: Any, msg: str):def decorator(func):@functools.wraps(func)def wrapper(aten_op, args, kwargs=None):if op == CompareOp.LT and not (len(args[k]) < value):raise NotImplementedError(msg + str(len(args[k])))elif op == CompareOp.EQ and not (len(args[k]) == value):raise Not...
1
3
4
23
0
179
191
179
null
[]
None
null
0
0
0
null
0
null
The function (expect_args_len_at_k) defined within the public class called public.The function start at line 179 and ends at 191. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [179.0] and does not return any value..
pytorch_ao
public
public
0
0
noop_detach
def noop_detach(func, *args, **kwargs):return args[0][0]
1
2
3
19
0
195
196
195
null
[]
None
null
0
0
0
null
0
null
The function (noop_detach) defined within the public class called public.The function start at line 195 and ends at 196. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [195.0] and does not return any value..
pytorch_ao
public
public
0
0
clone
def clone(func, *args, **kwargs):return to_nf4(args[0][0].get_original_weight())
1
2
3
26
0
200
201
200
null
[]
None
null
0
0
0
null
0
null
The function (clone) defined within the public class called public.The function start at line 200 and ends at 201. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [200.0] and does not return any value..
pytorch_ao
public
public
0
0
nf4_detach
def nf4_detach(aten_op, args, kwargs=None):nf4tensor = args[0]updated_attrs = apply_to_inner_tensors(nf4tensor, aten_op, args[1:], kwargs)return NF4Tensor(*construct_nf4_args(nf4tensor, updated_attrs))
1
4
3
44
2
209
212
209
null
['updated_attrs', 'nf4tensor']
None
null
0
0
0
null
0
null
The function (nf4_detach) defined within the public class called public.The function start at line 209 and ends at 212. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [209.0] and does not return any value..
pytorch_ao
public
public
0
0
nf4_empty_like
def nf4_empty_like(aten_op, args, kwargs=None):nf4tensor = args[0]updated_attrs = apply_to_inner_tensors(nf4tensor, aten_op, args[1:], kwargs)if kwargs is not None and len(kwargs):for key, value in kwargs.items():updated_attrs[key] = valuereturn NF4Tensor(*construct_nf4_args(nf4tensor, updated_attrs))
4
7
3
72
2
220
226
220
null
['updated_attrs', 'nf4tensor']
None
null
0
0
0
null
0
null
The function (nf4_empty_like) defined within the public class called public.The function start at line 220 and ends at 226. It contains 7 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [220.0] and does not return any value..
pytorch_ao
public
public
0
0
nf4_split
def nf4_split(aten_op, args, kwargs=None):if len(args) == 3 and args[2] != 0:raise NotImplementedError(f"aten.split(NF4Tensor, dim={args[2]})")nf4tensor = args[0]num_chunks = nf4tensor.size(0) // args[1]attr_to_chunks = {}for attr in _INNER_TENSOR_NAMES_FOR_SHARDING:inner_tensor = getattr(nf4tensor, attr)assert inner_t...
8
30
3
202
9
234
266
234
null
['updated_attrs', 'inner_tensor', 'orig_dim', 'chunked_size', 'nf4tensor', 'attr_to_chunks', 'nf4_chunks', 'chunks', 'num_chunks']
None
null
0
0
0
null
0
null
The function (nf4_split) defined within the public class called public.The function start at line 234 and ends at 266. It contains 30 lines of code and it has a cyclomatic complexity of 8. It takes 3 parameters, represented as [234.0] and does not return any value..
pytorch_ao
public
public
0
0
nf4_new_zeros
def nf4_new_zeros(aten_op, args, kwargs=None):nf4tensor = args[0]new_size = tuple(args[1])if nf4tensor.numel() % math.prod(new_size) != 0:raise NotImplementedError(f"aten.new_zeros(NF4Tensor) with new size {new_size}")ratio = nf4tensor.numel() // math.prod(new_size)updated_attrs = {}for attr in _INNER_TENSOR_NAMES_FOR_...
3
16
3
126
5
275
292
275
null
['updated_attrs', 'inner_tensor', 'new_size', 'nf4tensor', 'ratio']
None
null
0
0
0
null
0
null
The function (nf4_new_zeros) defined within the public class called public.The function start at line 275 and ends at 292. It contains 16 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [275.0] and does not return any value..
pytorch_ao
public
public
0
0
nf4_slice
def nf4_slice(aten_op, args, kwargs=None):nf4tensor = args[0]# for tensor 512 x 512, tensor[:, :512] dispatch to# aten.slice(dim = 0, end=sys.maxsize)if args[3] not in [nf4tensor.size(0), sys.maxsize]:raise NotImplementedError(f"aten.slice(NF4Tensor) with end={args[3]}")return NF4Tensor(*construct_nf4_args(nf4tensor))
2
5
3
52
1
303
309
303
null
['nf4tensor']
None
null
0
0
0
null
0
null
The function (nf4_slice) defined within the public class called public.The function start at line 303 and ends at 309. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [303.0] and does not return any value..
pytorch_ao
public
public
0
0
nf4_view
def nf4_view(aten_op, args, kwargs=None):nf4tensor = args[0]size = args[1]if len(size) == 1:if size[0] != -1:raise NotImplementedError(f"aten.view(NF4Tensor) with size={size}")else:updated_attrs = apply_to_inner_tensors(nf4tensor, aten_op, args[1:], kwargs)updated_attrs.update({"size": [nf4tensor.numel()],"stride": (1,...
6
31
3
197
4
318
348
318
null
['attr_size', 'updated_attrs', 'size', 'nf4tensor']
None
null
0
0
0
null
0
null
The function (nf4_view) defined within the public class called public.The function start at line 318 and ends at 348. It contains 31 lines of code and it has a cyclomatic complexity of 6. It takes 3 parameters, represented as [318.0] and does not return any value..
pytorch_ao
public
public
0
0
nf4_as_strided
def nf4_as_strided(aten_op, args, kwargs=None):nf4tensor = args[0]size = args[1]stride = tuple(args[2])storage_offset = args[3]if math.prod(size) != nf4tensor.numel():raise NotImplementedError(f"aten.as_strided(NF4Tensor) different numel={nf4tensor.numel()} and size={size}")if stride != make_contiguous_strides_for(size...
4
23
3
119
5
359
381
359
null
['kwargs', 'nf4tensor', 'storage_offset', 'size', 'stride']
None
null
0
0
0
null
0
null
The function (nf4_as_strided) defined within the public class called public.The function start at line 359 and ends at 381. It contains 23 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [359.0] and does not return any value..
pytorch_ao
public
public
0
0
_to_copy
def _to_copy(func, *args, **kwargs):if not args[0][0].is_contiguous():assert args[0][0].t().is_contiguous()return func(args[0][0].t()).t()out = args[0][0].get_original_weight().to(args[1]["dtype"])if "device" in args[1]:out = out.to(args[1]["device"])return out
3
8
3
108
1
385
392
385
null
['out']
None
null
0
0
0
null
0
null
The function (_to_copy) defined within the public class called public.The function start at line 385 and ends at 392. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 3 parameters, represented as [385.0] and does not return any value..
pytorch_ao
public
public
0
0
to_dtype
def to_dtype(func, *args, **kwargs):if not args[0][0].is_contiguous():assert args[0][0].t().is_contiguous()return torch.ops.aten.to.dtype(args[0][0].t(), args[0][1]).t()return args[0][0].get_original_weight().to(args[0][1])
2
5
3
99
0
396
400
396
null
[]
None
null
0
0
0
null
0
null
The function (to_dtype) defined within the public class called public.The function start at line 396 and ends at 400. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [396.0] and does not return any value..