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 | eos_id | def eos_id(self):return self.processor.eos_id() | 1 | 2 | 1 | 13 | 0 | 47 | 48 | 47 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (eos_id) defined within the public class called public.The function start at line 47 and ends at 48. 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 | __init__ | def __init__(self, model_path):import tiktokenimport tiktoken.loadsuper().__init__(model_path)assert os.path.isfile(model_path), str(model_path)mergeable_ranks = tiktoken.load.load_tiktoken_bpe(str(model_path))num_base_tokens = len(mergeable_ranks)special_tokens = ["<|begin_of_text|>","<|end_of_text|>","<|reserved_spec... | 3 | 35 | 2 | 192 | 0 | 62 | 98 | 62 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 62 and ends at 98. It contains 35 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [62.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | encode | def encode(self, text):return self.processor.EncodeAsIds(text) | 1 | 2 | 2 | 16 | 0 | 100 | 101 | 38 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (encode) defined within the public class called public.The function start at line 100 and ends at 101. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [38.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | decode | def decode(self, tokens):return self.processor.DecodeIds(tokens) | 1 | 2 | 2 | 16 | 0 | 103 | 104 | 41 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (decode) defined within the public class called public.The function start at line 103 and ends at 104. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [41.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | bos_id | def bos_id(self):return self._bos_id | 1 | 2 | 1 | 9 | 0 | 106 | 107 | 106 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (bos_id) defined within the public class called public.The function start at line 106 and ends at 107. 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 | eos_id | def eos_id(self):return self._eos_id | 1 | 2 | 1 | 9 | 0 | 109 | 110 | 109 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (eos_id) defined within the public class called public.The function start at line 109 and ends at 110. 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 | get_tokenizer | def get_tokenizer(tokenizer_model_path, model_name):"""Factory function to get the appropriate tokenizer based on the model name.Args:- tokenizer_model_path (str): The file path to the tokenizer model.- model_name (str): The name of the model, used to determine the tokenizer type.Returns:- TokenizerInterface: An instan... | 2 | 5 | 2 | 28 | 0 | 113 | 126 | 113 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_tokenizer) defined within the public class called public.The function start at line 113 and ends at 126. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [113.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | device_sync | def device_sync(device):if "cuda" in device:torch.cuda.synchronize(device)elif "cpu" in device:passelse:print(f"device={device} is not yet suppported") | 3 | 7 | 1 | 31 | 0 | 21 | 27 | 21 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (device_sync) defined within the public class called public.The function start at line 21 and ends at 27. It contains 7 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 | multinomial_sample_one_no_sync | def multinomial_sample_one_no_sync(probs_sort,):# Does multinomial sampling without a cuda synchronizationq = torch.empty_like(probs_sort).exponential_(1)return torch.argmax(probs_sort / q, dim=-1, keepdim=True).to(dtype=torch.int) | 1 | 5 | 1 | 46 | 1 | 43 | 47 | 43 | null | ['q'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (multinomial_sample_one_no_sync) defined within the public class called public.The function start at line 43 and ends at 47. 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 | logits_to_probs | def logits_to_probs(logits, temperature: float = 1.0, top_k: Optional[int] = None):logits = logits / max(temperature, 1e-5)if top_k is not None:v, _ = torch.topk(logits, min(top_k, logits.size(-1)))pivot = v.select(-1, -1).unsqueeze(-1)logits = torch.where(logits < pivot, -float("Inf"), logits)probs = torch.nn.function... | 2 | 8 | 3 | 118 | 3 | 50 | 58 | 50 | null | ['pivot', 'logits', 'probs'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (logits_to_probs) defined within the public class called public.The function start at line 50 and ends at 58. It contains 8 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [50.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | sample | def sample(logits, temperature: float = 1.0, top_k: Optional[int] = None):probs = logits_to_probs(logits[:, -1], temperature, top_k)idx_next = multinomial_sample_one_no_sync(probs)return idx_next, probs | 1 | 4 | 3 | 48 | 2 | 61 | 64 | 61 | null | ['probs', 'idx_next'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (sample) defined within the public class called public.The function start at line 61 and ends at 64. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [61.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | prefill | def prefill(model: Transformer, x: torch.Tensor, input_pos: torch.Tensor, **sampling_kwargs) -> torch.Tensor:# input_pos: [B, S]logits = model(x, input_pos)return sample(logits, **sampling_kwargs)[0] | 1 | 5 | 4 | 45 | 1 | 67 | 72 | 67 | null | ['logits'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (prefill) defined within the public class called public.The function start at line 67 and ends at 72. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [67.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | decode_one_token | def decode_one_token(model: Transformer, x: torch.Tensor, input_pos: torch.Tensor, **sampling_kwargs) -> Tuple[torch.Tensor, torch.Tensor]:# input_pos: [B, 1]assert input_pos.shape[-1] == 1logits = model(x, input_pos)return sample(logits, **sampling_kwargs) | 1 | 6 | 4 | 59 | 1 | 75 | 81 | 75 | null | ['logits'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (decode_one_token) defined within the public class called public.The function start at line 75 and ends at 81. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [75.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | decode_n_tokens | def decode_n_tokens(model: Transformer,cur_token: torch.Tensor,input_pos: torch.Tensor,num_new_tokens: int,callback=lambda _: _,**sampling_kwargs,):new_tokens, new_probs = [], []for i in range(num_new_tokens):with torch.backends.cuda.sdp_kernel(enable_flash=False, enable_mem_efficient=False, enable_math=True):# Actuall... | 2 | 23 | 6 | 141 | 1 | 84 | 108 | 84 | null | ['cur_token'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (decode_n_tokens) defined within the public class called public.The function start at line 84 and ends at 108. It contains 23 lines of code and it has a cyclomatic complexity of 2. It takes 6 parameters, represented as [84.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | model_forward | def model_forward(model, x, input_pos):return model(x, input_pos) | 1 | 2 | 3 | 16 | 0 | 111 | 112 | 111 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (model_forward) defined within the public class called public.The function start at line 111 and ends at 112. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [111.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | generate | def generate(model: Transformer,prompt: torch.Tensor,max_new_tokens: int,batch_size: int,*,interactive: bool,callback=lambda x: x,**sampling_kwargs,) -> torch.Tensor:"""Takes a conditioning sequence (prompt) as input and continues to generate as many tokens as requested."""device, _ = prompt.device, prompt.dtypeT = pro... | 2 | 37 | 7 | 275 | 7 | 116 | 164 | 116 | null | ['input_pos', 'seq', 'T', 'prompt', 'new_tokens', 'next_token', 'max_seq_length'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (generate) defined within the public class called public.The function start at line 116 and ends at 164. It contains 37 lines of code and it has a cyclomatic complexity of 2. It takes 7 parameters, represented as [116.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | encode_tokens | def encode_tokens(tokenizer, string, bos=True, device="cuda"):tokens = tokenizer.encode(string)if bos:tokens = [tokenizer.bos_id()] + tokensreturn torch.tensor(tokens, dtype=torch.int, device=device) | 2 | 5 | 4 | 54 | 1 | 167 | 171 | 167 | null | ['tokens'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (encode_tokens) defined within the public class called public.The function start at line 167 and ends at 171. It contains 5 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [167.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _load_model | def _load_model(checkpoint_path, device, precision):with torch.device("meta"):model = Transformer.from_name(checkpoint_path.parent.name)try:checkpoint = torch.load(str(checkpoint_path), mmap=True, weights_only=True)model.load_state_dict(checkpoint, assign=True)except:model = Transformer.from_name(checkpoint_path.parent... | 2 | 10 | 3 | 94 | 2 | 174 | 185 | 174 | null | ['checkpoint', 'model'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_load_model) defined within the public class called public.The function start at line 174 and ends at 185. It contains 10 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [174.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | main.callback | def callback(x):nonlocal done_generatingif done_generating:returnbuffer.append(tokenizer.decode([period_id] + x.tolist())[1:])if x.item() == tokenizer.eos_id():done_generating = Trueif len(buffer) == 4 or done_generating:print("".join(buffer), end="", flush=True)buffer.clear() | 5 | 10 | 1 | 82 | 0 | 365 | 374 | 365 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (main.callback) defined within the public class called public.The function start at line 365 and ends at 374. It contains 10 lines of code and it has a cyclomatic complexity of 5. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | main | def main(prompt: str = "Hello, my name is",interactive: bool = False,num_samples: int = 5,max_new_tokens: int = 100,batch_size: int = 1,top_k: int = 200,temperature: float = 0.8,checkpoint_path: Path = Path("checkpoints/mistralai/Mixtral-8x7B-v0.1/model.pth"),compile: bool = True,compile_prefill: bool = False,moe_quant... | 38 | 199 | 8 | 1,091 | 26 | 191 | 435 | 191 | null | ['config', 'callback', 't0', 'prof', 'encoded', 'tokenizer', 'tokpersec', 'model_size', 'tokenizer_path', 'prompt_length', 'precision', 'decode_one_token', 'period_id', 'aggregate_metrics', 'tokens_sec', 'snapshot', 'done_generating', 'prompt', 'prefill', 'is_chat', 'start', 't', 'model', 'buffer', 'y', 'tokens_generat... | None | null | 0 | 0 | 0 | null | 0 | null | The function (main) defined within the public class called public.The function start at line 191 and ends at 435. It contains 199 lines of code and it has a cyclomatic complexity of 38. It takes 8 parameters, represented as [191.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | find_multiple | def find_multiple(n: int, k: int) -> int:if n % k == 0:return nreturn n + k - (n % k) | 2 | 4 | 2 | 32 | 0 | 17 | 20 | 17 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (find_multiple) defined within the public class called public.The function start at line 17 and ends at 20. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [17.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __post_init__ | def __post_init__(self):if self.n_local_heads == -1:self.n_local_heads = self.n_headif self.intermediate_size is None:hidden_dim = 4 * self.dimn_hidden = int(2 * hidden_dim / 3)self.intermediate_size = find_multiple(n_hidden, 256)self.head_dim = self.dim // self.n_head | 3 | 8 | 1 | 62 | 0 | 38 | 45 | 38 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__post_init__) defined within the public class called public.The function start at line 38 and ends at 45. It contains 8 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 | from_name | def from_name(cls, name: str):if name in transformer_configs:return cls(**transformer_configs[name])# fuzzy searchconfig = [configfor config in transformer_configsif config in str(name).upper() or config in str(name)]assert len(config) == 1, namereturn cls(**transformer_configs[config[0]]) | 5 | 10 | 2 | 71 | 0 | 48 | 58 | 48 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_name) defined within the public class called public.The function start at line 48 and ends at 58. It contains 10 lines of code and it has a cyclomatic complexity of 5. It takes 2 parameters, represented as [48.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, max_batch_size, max_seq_length, n_heads, head_dim, dtype=torch.bfloat16):super().__init__()cache_shape = (max_batch_size, n_heads, max_seq_length, head_dim)self.register_buffer("k_cache", torch.zeros(cache_shape, dtype=dtype))self.register_buffer("v_cache", torch.zeros(cache_shape, dtype=dtype)) | 1 | 7 | 6 | 71 | 0 | 77 | 83 | 77 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 77 and ends at 83. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [77.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | update | def update(self, input_pos, k_val, v_val):# input_pos: [S], k_val: [B, H, S, D]assert input_pos.shape[0] == k_val.shape[2]k_out = self.k_cachev_out = self.v_cachek_out[:, :, input_pos] = k_valv_out[:, :, input_pos] = v_valreturn k_out, v_out | 1 | 7 | 4 | 59 | 0 | 85 | 94 | 85 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (update) defined within the public class called public.The function start at line 85 and ends at 94. It contains 7 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [85.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config: ModelArgs) -> None:super().__init__()self.config = configself.tok_embeddings = nn.Embedding(config.vocab_size, config.dim)self.layers = nn.ModuleList(TransformerBlock(config) for _ in range(config.n_layer))self.norm = RMSNorm(config.dim, eps=config.norm_eps)self.output = nn.Linear(config.dim,... | 2 | 13 | 2 | 129 | 0 | 98 | 112 | 98 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 98 and ends at 112. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [98.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | setup_caches | def setup_caches(self, max_batch_size, max_seq_length):if (self.max_seq_length >= max_seq_lengthand self.max_batch_size >= max_batch_size):returnhead_dim = self.config.dim // self.config.n_headmax_seq_length = find_multiple(max_seq_length, 8)self.max_seq_length = max_seq_lengthself.max_batch_size = max_batch_sizefor b ... | 4 | 22 | 3 | 130 | 0 | 114 | 136 | 114 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (setup_caches) defined within the public class called public.The function start at line 114 and ends at 136. It contains 22 lines of code and it has a cyclomatic complexity of 4. It takes 3 parameters, represented as [114.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, idx: Tensor, input_pos: Optional[Tensor] = None) -> Tensor:assert self.freqs_cis is not None, "Caches must be initialized first"mask = self.causal_mask[None, None, input_pos]freqs_cis = self.freqs_cis[input_pos]x = self.tok_embeddings(idx)for i, layer in enumerate(self.layers):x = layer(x, input_pos, ... | 2 | 10 | 3 | 99 | 0 | 138 | 148 | 138 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 138 and ends at 148. It contains 10 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [138.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_name | def from_name(cls, name: str):return cls(ModelArgs.from_name(name)) | 1 | 2 | 2 | 19 | 0 | 151 | 152 | 151 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_name) defined within the public class called public.The function start at line 151 and ends at 152. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [151.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config: ModelArgs) -> None:super().__init__()self.attention = Attention(config)self.block_sparse_moe = MOEFeedForwardAOQuantizable(config)self.ffn_norm = RMSNorm(config.dim, config.norm_eps)self.attention_norm = RMSNorm(config.dim, config.norm_eps) | 1 | 6 | 2 | 62 | 0 | 156 | 161 | 156 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 156 and ends at 161. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [156.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, x: Tensor, input_pos: Tensor, freqs_cis: Tensor, mask: Tensor) -> Tensor:h = x + self.attention(self.attention_norm(x), freqs_cis, mask, input_pos)out = h + self.block_sparse_moe(self.ffn_norm(h))return out | 1 | 6 | 5 | 61 | 0 | 163 | 168 | 163 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 163 and ends at 168. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [163.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config: ModelArgs):super().__init__()assert config.dim % config.n_head == 0total_head_dim = (config.n_head + 2 * config.n_local_heads) * config.head_dim# key, query, value projections for all heads, but in a batchself.wqkv = nn.Linear(config.dim, total_head_dim, bias=False)self.wo = nn.Linear(config.... | 1 | 12 | 2 | 122 | 0 | 172 | 186 | 172 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 172 and ends at 186. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [172.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | load_hook | def load_hook(self, state_dict, prefix, *args):if prefix + "wq.weight" in state_dict:wq = state_dict.pop(prefix + "wq.weight")wk = state_dict.pop(prefix + "wk.weight")wv = state_dict.pop(prefix + "wv.weight")state_dict[prefix + "wqkv.weight"] = torch.cat([wq, wk, wv]) | 2 | 6 | 4 | 68 | 0 | 188 | 193 | 188 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (load_hook) defined within the public class called public.The function start at line 188 and ends at 193. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 4 parameters, represented as [188.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self,x: Tensor,freqs_cis: Tensor,mask: Tensor,input_pos: Optional[Tensor] = None,) -> Tensor:bsz, seqlen, _ = x.shapekv_size = self.n_local_heads * self.head_dimq, k, v = self.wqkv(x).split([self.dim, kv_size, kv_size], dim=-1)q = q.view(bsz, seqlen, self.n_head, self.head_dim)k = k.view(bsz, seqlen, self.n... | 2 | 24 | 5 | 276 | 0 | 195 | 226 | 195 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 195 and ends at 226. It contains 24 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [195.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, dim: int, eps: float = 1e-5):super().__init__()self.eps = epsself.weight = nn.Parameter(torch.ones(dim)) | 1 | 4 | 3 | 44 | 0 | 266 | 269 | 266 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 266 and ends at 269. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [266.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _norm | def _norm(self, x):return x * torch.rsqrt(torch.mean(x * x, dim=-1, keepdim=True) + self.eps) | 1 | 2 | 2 | 36 | 0 | 271 | 272 | 271 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_norm) defined within the public class called public.The function start at line 271 and ends at 272. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [271.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, x: Tensor) -> Tensor:output = self._norm(x.float()).type_as(x)return output * self.weight | 1 | 3 | 2 | 34 | 0 | 274 | 276 | 274 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 274 and ends at 276. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [274.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | precompute_freqs_cis | def precompute_freqs_cis(seq_len: int, n_elem: int, base: int = 10000) -> Tensor:freqs = 1.0 / (base ** (torch.arange(0, n_elem, 2)[: (n_elem // 2)].float() / n_elem))t = torch.arange(seq_len, device=freqs.device)freqs = torch.outer(t, freqs)freqs_cis = torch.polar(torch.ones_like(freqs), freqs)cache = torch.stack([fre... | 1 | 9 | 3 | 116 | 4 | 279 | 287 | 279 | null | ['cache', 't', 'freqs', 'freqs_cis'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (precompute_freqs_cis) defined within the public class called public.The function start at line 279 and ends at 287. It contains 9 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [279.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | apply_rotary_emb | def apply_rotary_emb(x: Tensor, freqs_cis: Tensor) -> Tensor:xshaped = x.float().reshape(*x.shape[:-1], -1, 2)freqs_cis = freqs_cis.view(1, xshaped.size(1), 1, xshaped.size(3), 2)x_out2 = torch.stack([xshaped[..., 0] * freqs_cis[..., 0] - xshaped[..., 1] * freqs_cis[..., 1],xshaped[..., 1] * freqs_cis[..., 0] + xshaped... | 1 | 12 | 2 | 148 | 3 | 290 | 302 | 290 | null | ['xshaped', 'x_out2', 'freqs_cis'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (apply_rotary_emb) defined within the public class called public.The function start at line 290 and ends at 302. It contains 12 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [290.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config) -> None:super().__init__()self.gate = nn.Linear(config.dim, config.num_experts, bias=False)self.cond_ffn = ConditionalFeedForwardAOQuantizable(config)self.dim = config.dimself.num_activated_experts = config.num_activated_experts | 1 | 6 | 2 | 58 | 0 | 314 | 319 | 314 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 314 and ends at 319. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [314.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self, x: Tensor) -> Tensor:batch_size = x.shape[0]x = x.view(-1, self.dim)# x: [T, D]scores = self.gate(x)# [T, E]expert_weights = F.softmax(scores, dim=-1)expert_weights, expert_indices = torch.topk(expert_weights, self.num_activated_experts, dim=-1)# [T, A], [T, A]expert_weights /= expert_weights.sum(dim=... | 1 | 13 | 2 | 125 | 0 | 321 | 333 | 321 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 321 and ends at 333. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [321.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self, config):super().__init__()self.config = configself.w1 = nn.Parameter(torch.empty(config.num_experts, config.intermediate_size, config.dim))# E, I, Dself.w2 = nn.Parameter(torch.empty(config.num_experts, config.dim, config.intermediate_size))# E, D, Iself.w3 = nn.Parameter(torch.empty(config.num_exper... | 1 | 13 | 2 | 101 | 0 | 337 | 349 | 337 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 337 and ends at 349. It contains 13 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [337.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward.group_tokens_by_expert | def group_tokens_by_expert(ordered_token_indices, cum_tokens_per_expert, expert_list):token_indices_per_expert = [ordered_token_indices[cum_tokens_per_expert[expert] : cum_tokens_per_expert[expert + 1]]for expert in expert_list]# [T'(e1)], [T'(e2)] ...return token_indices_per_expert | 2 | 12 | 3 | 33 | 0 | 414 | 425 | 414 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward.group_tokens_by_expert) defined within the public class called public.The function start at line 414 and ends at 425. It contains 12 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [414.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | forward | def forward(self,x: Tensor,# T, Dexpert_indices: Tensor,# T, Aexpert_weights: Tensor,# T, Anum_activated_experts: int,) -> Tensor:num_tokens, dim = x.shapenum_token_activations = num_tokens * num_activated_expertsif x.shape[0] == 1 and not isinstance(self.w1, FakeExtraDimTensor):# only 1 token (can be done without grap... | 8 | 86 | 5 | 523 | 0 | 351 | 464 | 351 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (forward) defined within the public class called public.The function start at line 351 and ends at 464. It contains 86 lines of code and it has a cyclomatic complexity of 8. It takes 5 parameters, represented as [351.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | convert_hf_checkpoint | def convert_hf_checkpoint(*,checkpoint_dir: Path = Path("checkpoints/mistralai/Mixtral-8x7B-v0.1"),model_name: Optional[str] = None,) -> None:if model_name is None:model_name = checkpoint_dir.nameconfig = ModelArgs.from_name(model_name)print(f"Model config {config.__dict__}")weight_map = {"tok_embeddings.weight": "tok_... | 12 | 69 | 1 | 460 | 13 | 22 | 97 | 22 | null | ['config', 'weight_map', 'q', 'state_dict', 'final_result', 'layer_num', 'new_key', 'abstract_key', 'k', 'v', 'pt_files', 'merged_result', 'model_name'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (convert_hf_checkpoint) defined within the public class called public.The function start at line 22 and ends at 97. It contains 69 lines of code and it has a cyclomatic complexity of 12. The function does not take any parameters and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | hf_download | def hf_download(repo_id: Optional[str] = None, hf_token: Optional[str] = None) -> None:from huggingface_hub import snapshot_downloados.makedirs(f"checkpoints/{repo_id}", exist_ok=True)try:snapshot_download(repo_id,local_dir=f"checkpoints/{repo_id}",local_dir_use_symlinks=False,token=hf_token,ignore_patterns="*.safetens... | 3 | 18 | 2 | 84 | 0 | 12 | 30 | 12 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (hf_download) defined within the public class called public.The function start at line 12 and ends at 30. It contains 18 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [12.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _get_center_point | def _get_center_point(mask, ann_id, cache):"""This is a rudimentary version of https://arxiv.org/pdf/2304.02643.pdf,section D.1.Point SamplingFrom the paper: "The first point is chosen deterministically as the pointfarthest from the object boundary."The code below is an approximation of this.First, we try to calculate ... | 21 | 59 | 3 | 354 | 10 | 15 | 127 | 15 | null | ['cur_col_idx', 'DISTANCE_GOOD_ENOUGH_THRESHOLD', 'max_distances', 'distance', 'global_coords', 'global_min_max_distance', 'cur_point', 'min_max_distance', 'cur_row_idx', 'distances_to_check_deg'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_get_center_point) defined within the public class called public.The function start at line 15 and ends at 127. It contains 59 lines of code and it has a cyclomatic complexity of 21. It takes 3 parameters, represented as [15.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | build_datapoint | def build_datapoint(imgId,coco,pixel_mean,pixel_std,coco_root_dir,coco_slice_name,catIds,cache,predictor,pad_input_image_batch,):img = coco.loadImgs(imgId)[0]file_location = f"{coco_root_dir}/{coco_slice_name}/{img['file_name']}"I = io.imread(file_location)if len(I.shape) == 2:# some images, like img_id==61418, are gra... | 5 | 43 | 10 | 312 | 17 | 130 | 189 | 130 | null | ['image', 'anns', 'I', 'img', 'input_image_torch', 'predictor_input_size', 'x', 'gt_masks_list', 'mask', 'ann_id', 'coords_list', 'annIds', 'coords', 'input_image', 'padh', 'padw', 'file_location'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_datapoint) defined within the public class called public.The function start at line 130 and ends at 189. It contains 43 lines of code and it has a cyclomatic complexity of 5. It takes 10 parameters, represented as [130.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | build_data.build_data.build_batch.cat_and_cast | def cat_and_cast(b, use_half):b = torch.cat(b) if len(b) > 0 else Noneif use_half is not None and b is not None:return b.to(use_half)return b | 4 | 5 | 2 | 44 | 0 | 252 | 256 | 252 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_data.build_data.build_batch.cat_and_cast) defined within the public class called public.The function start at line 252 and ends at 256. It contains 5 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [252.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | build_data.build_data.build_batch.to_nested_tensor | def to_nested_tensor(data, sizes=None, use_half=None):if len(data) == 0:return Nonedtype = use_half if use_half is not None else torch.float32if sizes is not None:data = [d.view(s) for (d, s) in zip(data, sizes)]return torch.nested.nested_tensor(data, dtype=dtype, layout=torch.jagged) | 5 | 7 | 3 | 83 | 0 | 258 | 266 | 258 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_data.build_data.build_batch.to_nested_tensor) defined within the public class called public.The function start at line 258 and ends at 266. It contains 7 lines of code and it has a cyclomatic complexity of 5. It takes 3 parameters, represented as [258.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | build_data.build_batch | def build_batch(indicies):batch = [[], [], [], [], [], [], [], [], [], [], []]batch[3] = [0]batch[6] = [0]for img_idx in indicies:imgId = coco_img_ids[img_idx]datapoint = build_datapoint(imgId,coco,pixel_mean,pixel_std,coco_root_dir,coco_slice_name,catIds,cache,predictor,pad_input_image_batch,)I, coords_list, gt_masks_... | 4 | 45 | 1 | 366 | 0 | 210 | 277 | 210 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_data.build_batch) defined within the public class called public.The function start at line 210 and ends at 277. It contains 45 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 | build_data | def build_data(coco_img_ids,coco,catIds,coco_root_dir,coco_slice_name,point_sampling_cache_dir,predictor,use_half,pad_input_image_batch,):cache = diskcache.Cache(point_sampling_cache_dir)# make sure you clear the cache if you change the point sampling algorithm# cache.clear()pixel_mean = predictor.model.pixel_mean.cpu(... | 1 | 16 | 9 | 56 | 10 | 192 | 279 | 192 | null | ['imgId', 'batch', 'cache', 'pixel_std', 'datapoint', 'pixel_mean', 'b', 'dtype', 'data', 'coords_list'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_data) defined within the public class called public.The function start at line 192 and ends at 279. It contains 16 lines of code and it has a cyclomatic complexity of 1. It takes 9 parameters, represented as [192.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | setup_coco_img_ids | def setup_coco_img_ids(coco_root_dir, coco_slice_name, coco_category_names, img_id):annFile = "{}/annotations/instances_{}.json".format(coco_root_dir, coco_slice_name)# initialize COCO api for instance annotationscoco = COCO(annFile)# display COCO categories and supercategoriescats = coco.loadCats(coco.getCatIds())cat_... | 5 | 16 | 4 | 121 | 6 | 282 | 308 | 282 | null | ['annFile', 'coco', 'catIds', 'cat_id_to_cat', 'cats', 'coco_img_ids'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (setup_coco_img_ids) defined within the public class called public.The function start at line 282 and ends at 308. It contains 16 lines of code and it has a cyclomatic complexity of 5. It takes 4 parameters, represented as [282.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | unbind_jagged | def unbind_jagged(device, data, sizes, offsets):if data is None:return Nonedata = data.to(device=device, non_blocking=True)return [data[offsets[batch_idx] : offsets[batch_idx + 1]].view(sizes[batch_idx])for batch_idx in range(len(sizes))] | 3 | 8 | 4 | 67 | 1 | 35 | 42 | 35 | null | ['data'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (unbind_jagged) defined within the public class called public.The function start at line 35 and ends at 42. It contains 8 lines of code and it has a cyclomatic complexity of 3. It takes 4 parameters, represented as [35.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | pad_to_batch_size | def pad_to_batch_size(batch, batch_size, device):assert batch.dim() == 4# assert batch.is_pinned()global PADDED_TENSORif PADDED_TENSOR is None:batch = batch.to(device=device, non_blocking=True)full_batch_size = (batch_size, batch.size(1), batch.size(2), batch.size(3))first_entry = batch[0].unsqueeze(0)repeat_first_entr... | 2 | 15 | 3 | 141 | 6 | 49 | 64 | 49 | null | ['batch', 'repeat_first_entry', 'full_batch_size', 'first_entry', 'padded_batch', 'PADDED_TENSOR'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (pad_to_batch_size) defined within the public class called public.The function start at line 49 and ends at 64. It contains 15 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [49.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | get_features_batch | def get_features_batch(encoder, input_image_batch, pad_input_image_batch, batch_size, device):if pad_input_image_batch:features_batch = encoder(pad_to_batch_size(input_image_batch, batch_size, device))return features_batch[: input_image_batch.size(0)]return encoder(input_image_batch) | 2 | 9 | 5 | 45 | 1 | 67 | 75 | 67 | null | ['features_batch'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (get_features_batch) defined within the public class called public.The function start at line 67 and ends at 75. It contains 9 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [67.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | build_results_batch | def build_results_batch(predictor, batch, batch_size, pad_input_image_batch):encoder = predictor.model.image_encoderdevice = predictor.deviceinput_image_batch = batch[0]# The number of valid data points varies slightly per batchorig_input_image_batch_size = input_image_batch.size(0)if input_image_batch is None:return (... | 7 | 62 | 4 | 456 | 17 | 78 | 154 | 78 | null | ['features', 'fg_labels', 'elapsed_time', 't0', 'encoder', 'gt_masks_lists', 'device', 'coords_lists', 'result_batch', 'end_event', 'coords', 'entry', 'start_event', 'orig_input_image_batch_size', 'datapoints', 'features_batch', 'input_image_batch'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_results_batch) defined within the public class called public.The function start at line 78 and ends at 154. It contains 62 lines of code and it has a cyclomatic complexity of 7. It takes 4 parameters, represented as [78.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | build_results | def build_results(batched_data_iter,predictor,mask_debug_out_dir,batch_size,use_compile,use_compile_decoder,pad_input_image_batch,compress,use_fullgraph=False,):# TODO: Re-enable this for datapointsassert not use_compile_decoderbatch_runner = build_results_batchresults = []batch_idx = 0num_images = 0num_batches = 0elap... | 9 | 52 | 9 | 215 | 9 | 157 | 220 | 157 | null | ['elapsed_time', '_', 'avg_ms_per_img', 'num_batches', 'results', 'batch_runner', 'partial_batch', 'batch_idx', 'num_images'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_results) defined within the public class called public.The function start at line 157 and ends at 220. It contains 52 lines of code and it has a cyclomatic complexity of 9. It takes 9 parameters, represented as [157.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | identity_runner | def identity_runner(fn, *args, **kwargs):return fn(*args, **kwargs) | 1 | 2 | 3 | 20 | 0 | 223 | 224 | 223 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (identity_runner) defined within the public class called public.The function start at line 223 and ends at 224. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [223.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | profiler_runner | def profiler_runner(path, fn, *args, **kwargs):with torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU,torch.profiler.ProfilerActivity.CUDA,],record_shapes=True,) as prof:result = fn(*args, **kwargs)prof.export_chrome_trace(path)return result | 1 | 11 | 4 | 67 | 1 | 227 | 237 | 227 | null | ['result'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (profiler_runner) defined within the public class called public.The function start at line 227 and ends at 237. It contains 11 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [227.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | profile_top_runner | def profile_top_runner(fn, *args, **kwargs):with torch.profiler.profile(activities=[torch.profiler.ProfilerActivity.CPU,torch.profiler.ProfilerActivity.CUDA,],record_shapes=True,) as prof:result = fn(*args, **kwargs)if torch.cuda.is_available():print(prof.key_averages().table(sort_by="self_cuda_time_total", row_limit=-... | 2 | 14 | 3 | 110 | 1 | 240 | 253 | 240 | null | ['result'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (profile_top_runner) defined within the public class called public.The function start at line 240 and ends at 253. It contains 14 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [240.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | memory_runner | def memory_runner(path, fn, *args, **kwargs):print("Start memory recording")torch.cuda.synchronize()torch.cuda.memory._record_memory_history(True, trace_alloc_max_entries=100000, trace_alloc_record_context=True)result = fn(*args, **kwargs)torch.cuda.synchronize()snapshot = torch.cuda.memory._snapshot()print("Finish mem... | 1 | 14 | 4 | 96 | 2 | 256 | 272 | 256 | null | ['result', 'snapshot'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (memory_runner) defined within the public class called public.The function start at line 256 and ends at 272. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [256.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | run.attn_only | def attn_only(mod, name):return isinstance(mod, torch.nn.Linear) and "attn" in name | 2 | 2 | 2 | 22 | 0 | 352 | 353 | 352 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (run.attn_only) defined within the public class called public.The function start at line 352 and ends at 353. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [352.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | run.mlp_lin1_only | def mlp_lin1_only(mod, name):return isinstance(mod, torch.nn.Linear) and "lin1" in name | 2 | 2 | 2 | 22 | 0 | 355 | 356 | 355 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (run.mlp_lin1_only) defined within the public class called public.The function start at line 355 and ends at 356. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [355.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | run.mlp_lin2_only | def mlp_lin2_only(mod, name):return isinstance(mod, torch.nn.Linear) and "lin2" in name | 2 | 2 | 2 | 22 | 0 | 358 | 359 | 358 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (run.mlp_lin2_only) defined within the public class called public.The function start at line 358 and ends at 359. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [358.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | run.mlp_only | def mlp_only(mod, name):return isinstance(mod, torch.nn.Linear) and "mlp" in name | 2 | 2 | 2 | 22 | 0 | 361 | 362 | 361 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (run.mlp_only) defined within the public class called public.The function start at line 361 and ends at 362. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [361.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | run.mlp_only | def mlp_only(mod, name):return isinstance(mod, torch.nn.Linear) and "mlp" in name | 2 | 2 | 2 | 22 | 0 | 370 | 371 | 361 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (run.mlp_only) defined within the public class called public.The function start at line 370 and ends at 371. It contains 2 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [361.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | run | def run(coco_root_dir,coco_slice_name,sam_checkpoint_base_path,sam_model_type,point_sampling_cache_dir,mask_debug_out_dir,batch_size=1,print_header=False,coco_category_names=None,limit=None,img_id=None,use_half=None,use_compile="False",use_compile_decoder=False,compress=None,min_sqnr=None,num_workers=0,use_rel_pos=True... | 34 | 353 | 25 | 1,540 | 31 | 275 | 677 | 275 | null | ['max_memory_allocated_bytes', 'mIoU', 'sam', 'coco_img_ids', 'use_half', 'memory_result', 'header', 'anns', 'results', 'build_batch', 'write_json_result', 'predictor', 'model_type_to_checkpoint', 'vals', 'example_input', 'max_memory_allocated_percentage', 'runner', 'headers', 'dtype', 'compile', 'name', 'annIds', 'bat... | None | null | 0 | 0 | 0 | null | 0 | null | The function (run) defined within the public class called public.The function start at line 275 and ends at 677. It contains 353 lines of code and it has a cyclomatic complexity of 34. It takes 25 parameters, represented as [275.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | create_result_entry._iou | def _iou(mask1, mask2):assert mask1.dim() == 3assert mask2.dim() == 3intersection = torch.logical_and(mask1, mask2)union = torch.logical_or(mask1, mask2)return intersection.sum(dim=(-1, -2)) / union.sum(dim=(-1, -2)) | 1 | 6 | 2 | 73 | 0 | 20 | 25 | 20 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (create_result_entry._iou) defined within the public class called public.The function start at line 20 and ends at 25. It contains 6 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [20.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | create_result_entry | def create_result_entry(anns, gt_masks_list, masks, scores, img_idx):argmax_scores = torch.argmax(scores, dim=1)inference_masks = masks.gather(1,argmax_scores.unsqueeze(-1).unsqueeze(-1).unsqueeze(-1).expand((masks.size(0), 1, masks.size(2), masks.size(3))),).squeeze(1)def _iou(mask1, mask2):assert mask1.dim() == 3asse... | 2 | 17 | 5 | 145 | 6 | 10 | 34 | 10 | null | ['union', 'entry', 'intersection', 'argmax_scores', 'inference_masks', 'top_score_ious'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (create_result_entry) defined within the public class called public.The function start at line 10 and ends at 34. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [10.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | calculate_miou | def calculate_miou(results, mask_debug_out_dir, silent, cat_id_to_cat):df = pd.DataFrame(results, columns=["img_id", "ann_id", "cat_id", "iou"])df.to_csv(f"{mask_debug_out_dir}/df.csv")df["supercategory"] = df["cat_id"].map(lambda cat_id: cat_id_to_cat[cat_id]["supercategory"])df["category"] = df["cat_id"].map(lambda c... | 4 | 27 | 4 | 209 | 4 | 37 | 76 | 37 | null | ['df', 'per_category', 'per_all_masks_agg', 'per_supercategory'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (calculate_miou) defined within the public class called public.The function start at line 37 and ends at 76. It contains 27 lines of code and it has a cyclomatic complexity of 4. It takes 4 parameters, represented as [37.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | __init__ | def __init__(self,model: SAM2Base,points_per_side: Optional[int] = 32,points_per_batch: int = 64,pred_iou_thresh: float = 0.8,stability_score_thresh: float = 0.95,stability_score_offset: float = 1.0,mask_threshold: float = 0.0,box_nms_thresh: float = 0.7,crop_n_layers: int = 0,crop_nms_thresh: float = 0.7,crop_overlap_... | 5 | 67 | 19 | 332 | 0 | 43 | 162 | 43 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (__init__) defined within the public class called public.The function start at line 43 and ends at 162. It contains 67 lines of code and it has a cyclomatic complexity of 5. It takes 19 parameters, represented as [43.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | from_pretrained | def from_pretrained(cls, model_id: str, **kwargs) -> "SAM2AutomaticMaskGenerator":"""Load a pretrained model from the Hugging Face hub.Arguments:model_id (str): The Hugging Face repository ID.**kwargs: Additional arguments to pass to the model constructor.Returns:(SAM2AutomaticMaskGenerator): The loaded model."""from s... | 1 | 4 | 3 | 38 | 0 | 165 | 179 | 165 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (from_pretrained) defined within the public class called public.The function start at line 165 and ends at 179. It contains 4 lines of code and it has a cyclomatic complexity of 1. It takes 3 parameters, represented as [165.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | generate | def generate(self, image: np.ndarray) -> List[Dict[str, Any]]:"""Generates masks for the given image.Arguments:image (np.ndarray): The image to generate masks for, in HWC uint8 format.Returns: list(dict(str, any)): A list over records for masks. Each record is a dict containing the following keys: segmentation (dict(st... | 1 | 3 | 2 | 37 | 0 | 182 | 210 | 182 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (generate) defined within the public class called public.The function start at line 182 and ends at 210. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [182.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _encode_masks | def _encode_masks(self, mask_data):mask_data["rles"] = _mask_to_rle_pytorch_2_1(mask_data["rles"])# Encode masksif self.output_mode == "coco_rle":mask_data["segmentations"] = [coco_encode_rle(rle) for rle in mask_data["rles"]]elif self.output_mode == "binary_mask":mask_data["segmentations"] = [rle_to_mask(rle) for rle ... | 6 | 23 | 2 | 211 | 0 | 212 | 238 | 212 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_encode_masks) defined within the public class called public.The function start at line 212 and ends at 238. It contains 23 lines of code and it has a cyclomatic complexity of 6. It takes 2 parameters, represented as [212.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | generate_batch | def generate_batch(self, images: List[np.ndarray]) -> List[List[Dict[str, Any]]]:data = self._generate_masks_batch(images)return [self._encode_masks(d) for d in data] | 2 | 3 | 2 | 48 | 0 | 241 | 243 | 241 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (generate_batch) defined within the public class called public.The function start at line 241 and ends at 243. It contains 3 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [241.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _generate_masks | def _generate_masks(self, image: Union[np.ndarray, torch.Tensor]) -> MaskData:orig_size = get_image_size(image)crop_boxes, layer_idxs = generate_crop_boxes(orig_size, self.crop_n_layers, self.crop_overlap_ratio)# Iterate over image cropsdata = Nonefor crop_box, layer_idx in zip(crop_boxes, layer_idxs):crop_data = self.... | 3 | 13 | 2 | 96 | 0 | 245 | 260 | 245 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_generate_masks) defined within the public class called public.The function start at line 245 and ends at 260. It contains 13 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [245.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _deduplicate_masks | def _deduplicate_masks(self, crop_boxes, data):# Remove duplicate masks between cropsif len(crop_boxes) > 1:# Prefer masks from smaller cropsscores = 1 / box_area(data["crop_boxes"])scores = scores.to(data["boxes"].device)keep_by_nms = batched_nms(data["boxes"].float(),scores,torch.zeros_like(data["boxes"][:, 0]),# cat... | 2 | 13 | 3 | 91 | 0 | 262 | 276 | 262 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_deduplicate_masks) defined within the public class called public.The function start at line 262 and ends at 276. It contains 13 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [262.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _generate_masks_batch | def _generate_masks_batch(self, images: List[np.ndarray]) -> List[MaskData]:all_orig_size = []all_crop_boxes = []all_layer_idxs = []for image in images:orig_size = get_image_size(image)all_orig_size.append(orig_size)crop_boxes, layer_idxs = generate_crop_boxes(orig_size, self.crop_n_layers, self.crop_overlap_ratio)all_... | 3 | 19 | 2 | 114 | 0 | 278 | 298 | 278 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_generate_masks_batch) defined within the public class called public.The function start at line 278 and ends at 298. It contains 19 lines of code and it has a cyclomatic complexity of 3. It takes 2 parameters, represented as [278.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _process_crop | def _process_crop(self,image: np.ndarray,crop_box: List[int],crop_layer_idx: int,orig_size: Tuple[int, ...],) -> MaskData:# Crop the image and calculate embeddingscropped_im = crop_image(image, crop_box)cropped_im_size = get_image_size(cropped_im)with torch.autograd.profiler.record_function("set_image"):self.predictor.... | 1 | 14 | 5 | 81 | 0 | 300 | 315 | 300 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_process_crop) defined within the public class called public.The function start at line 300 and ends at 315. It contains 14 lines of code and it has a cyclomatic complexity of 1. It takes 5 parameters, represented as [300.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _process_crop_points | def _process_crop_points(self, cropped_im_size, crop_layer_idx, crop_box, orig_size):# Get points for this croppoints_scale = np.array(cropped_im_size)[None, ::-1]points_for_image = self.point_grids[crop_layer_idx] * points_scale# Generate masks for this crop in batches# data = MaskData()data = Nonepoints_per_batch = s... | 4 | 21 | 5 | 136 | 0 | 317 | 341 | 317 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_process_crop_points) defined within the public class called public.The function start at line 317 and ends at 341. It contains 21 lines of code and it has a cyclomatic complexity of 4. It takes 5 parameters, represented as [317.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _process_crop_points_dedup | def _process_crop_points_dedup(self, data, crop_box):with torch.autograd.profiler.record_function("batched_nms"):# Remove duplicates within this crop.keep_by_nms = batched_nms(data["boxes"].float(),data["iou_preds"],torch.zeros_like(data["boxes"][:, 0]),# categoriesiou_threshold=self.box_nms_thresh,)with torch.autograd... | 2 | 19 | 3 | 171 | 0 | 343 | 366 | 343 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_process_crop_points_dedup) defined within the public class called public.The function start at line 343 and ends at 366. It contains 19 lines of code and it has a cyclomatic complexity of 2. It takes 3 parameters, represented as [343.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _process_crop_batch | def _process_crop_batch(self,images: List[np.ndarray],all_crop_boxes: List[List[int]],all_layer_idxs: List[int],all_orig_size_compact: List[Tuple[int, ...]],) -> List[MaskData]:all_image = []all_crop_box = []all_layer_idx = []all_orig_size = []for image, orig_size, crop_boxes, layer_idxs in zip(images, all_orig_size_co... | 13 | 102 | 5 | 626 | 0 | 368 | 500 | 368 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_process_crop_batch) defined within the public class called public.The function start at line 368 and ends at 500. It contains 102 lines of code and it has a cyclomatic complexity of 13. It takes 5 parameters, represented as [368.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _process_batch_fullgraph | def _process_batch_fullgraph(self,points: np.ndarray,im_size: Tuple[int, ...],crop_box: List[int],crop_box_torch: torch.Tensor,orig_size: Tuple[int, ...],normalize: bool,orig_box_torch: torch.Tensor,) -> MaskData:orig_h, orig_w = orig_size# Run model on this batchpoints = torch.as_tensor(points, dtype=torch.float32).pi... | 11 | 113 | 8 | 891 | 0 | 502 | 647 | 502 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_process_batch_fullgraph) defined within the public class called public.The function start at line 502 and ends at 647. It contains 113 lines of code and it has a cyclomatic complexity of 11. It takes 8 parameters, represented as [502.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _process_batch | def _process_batch(self,points: np.ndarray,im_size: Tuple[int, ...],crop_box: List[int],orig_size: Tuple[int, ...],normalize=False,) -> MaskData:orig_h, orig_w = orig_sizeorig_box = [0, 0, orig_w, orig_h]orig_box_torch = torch.as_tensor(orig_box, dtype=torch.float)orig_box_torch = orig_box_torch.pin_memory()orig_box_to... | 1 | 34 | 6 | 207 | 0 | 649 | 688 | 649 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_process_batch) defined within the public class called public.The function start at line 649 and ends at 688. It contains 34 lines of code and it has a cyclomatic complexity of 1. It takes 6 parameters, represented as [649.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | postprocess_small_regions | def postprocess_small_regions(mask_data: MaskData, min_area: int, nms_thresh: float) -> MaskData:"""Removes small disconnected regions and holes in masks, then rerunsbox NMS to remove any new duplicates.Edits mask_data in place.Requires open-cv as a dependency."""if len(mask_data["rles"]) == 0:return mask_data# Filter ... | 6 | 30 | 3 | 229 | 0 | 691 | 740 | 691 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (postprocess_small_regions) defined within the public class called public.The function start at line 691 and ends at 740. It contains 30 lines of code and it has a cyclomatic complexity of 6. It takes 3 parameters, represented as [691.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | refine_with_m2m | def refine_with_m2m(self, points, point_labels, low_res_masks, points_per_batch):new_masks = []new_iou_preds = []for cur_points, cur_point_labels, low_res_mask in batch_iterator(points_per_batch, points, point_labels, low_res_masks):best_masks, best_iou_preds, _ = self.predictor._predict(cur_points[:, None, :],cur_poin... | 2 | 17 | 5 | 124 | 0 | 742 | 759 | 742 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (refine_with_m2m) defined within the public class called public.The function start at line 742 and ends at 759. It contains 17 lines of code and it has a cyclomatic complexity of 2. It takes 5 parameters, represented as [742.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | build_sam2 | def build_sam2(config_file,ckpt_path=None,device="cuda",mode="eval",hydra_overrides_extra=[],apply_postprocessing=True,**kwargs,):if apply_postprocessing:hydra_overrides_extra = hydra_overrides_extra.copy()hydra_overrides_extra += [# dynamically fall back to multi-mask if the single mask is not stable"++model.sam_mask_... | 3 | 24 | 7 | 106 | 3 | 71 | 96 | 71 | null | ['hydra_overrides_extra', 'cfg', 'model'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_sam2) defined within the public class called public.The function start at line 71 and ends at 96. It contains 24 lines of code and it has a cyclomatic complexity of 3. It takes 7 parameters, represented as [71.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | build_sam2_video_predictor | def build_sam2_video_predictor(config_file,ckpt_path=None,device="cuda",mode="eval",hydra_overrides_extra=[],apply_postprocessing=True,**kwargs,):hydra_overrides = ["++model._target_=torchao._models.sam2.sam2_video_predictor.SAM2VideoPredictor",]if apply_postprocessing:hydra_overrides_extra = hydra_overrides_extra.copy... | 3 | 30 | 7 | 122 | 4 | 99 | 133 | 99 | null | ['hydra_overrides_extra', 'cfg', 'hydra_overrides', 'model'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_sam2_video_predictor) defined within the public class called public.The function start at line 99 and ends at 133. It contains 30 lines of code and it has a cyclomatic complexity of 3. It takes 7 parameters, represented as [99.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _hf_download | def _hf_download(model_id):from huggingface_hub import hf_hub_downloadconfig_name, checkpoint_name = HF_MODEL_ID_TO_FILENAMES[model_id]ckpt_path = hf_hub_download(repo_id=model_id, filename=checkpoint_name)return config_name, ckpt_path | 1 | 5 | 1 | 33 | 1 | 136 | 141 | 136 | null | ['ckpt_path'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_hf_download) defined within the public class called public.The function start at line 136 and ends at 141. 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 | build_sam2_hf | def build_sam2_hf(model_id, **kwargs):config_name, ckpt_path = _hf_download(model_id)return build_sam2(config_file=config_name, ckpt_path=ckpt_path, **kwargs) | 1 | 3 | 2 | 30 | 0 | 144 | 146 | 144 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_sam2_hf) defined within the public class called public.The function start at line 144 and ends at 146. It contains 3 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [144.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | build_sam2_video_predictor_hf | def build_sam2_video_predictor_hf(model_id, **kwargs):config_name, ckpt_path = _hf_download(model_id)return build_sam2_video_predictor(config_file=config_name, ckpt_path=ckpt_path, **kwargs) | 1 | 5 | 2 | 30 | 0 | 149 | 153 | 149 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (build_sam2_video_predictor_hf) defined within the public class called public.The function start at line 149 and ends at 153. It contains 5 lines of code and it has a cyclomatic complexity of 1. It takes 2 parameters, represented as [149.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | _load_checkpoint | def _load_checkpoint(model, ckpt_path):if ckpt_path is not None:sd = torch.load(ckpt_path, map_location="cpu", weights_only=True)["model"]missing_keys, unexpected_keys = model.load_state_dict(sd)if missing_keys:logging.error(missing_keys)raise RuntimeError()if unexpected_keys:logging.error(unexpected_keys)raise Runtime... | 4 | 11 | 2 | 74 | 1 | 156 | 166 | 156 | null | ['sd'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (_load_checkpoint) defined within the public class called public.The function start at line 156 and ends at 166. It contains 11 lines of code and it has a cyclomatic complexity of 4. It takes 2 parameters, represented as [156.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | implements.implements.decorator.wrapper | def wrapper(f, types, args, kwargs):return func(f, types, args, kwargs) | 1 | 2 | 4 | 22 | 0 | 25 | 26 | 25 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (implements.implements.decorator.wrapper) defined within the public class called public.The function start at line 25 and ends at 26. It contains 2 lines of code and it has a cyclomatic complexity of 1. It takes 4 parameters, represented as [25.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | implements.decorator | def decorator(func):for op in aten_ops_or_torch_fns:@functools.wraps(op)def wrapper(f, types, args, kwargs):return func(f, types, args, kwargs)MAP_TENSOR_ATEN_OP_TABLE[op] = wrapperreturn func | 2 | 6 | 1 | 27 | 0 | 21 | 29 | 21 | 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 21 and ends at 29. It contains 6 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_or_torch_fns):if not isinstance(aten_ops_or_torch_fns, (list, tuple)):aten_ops_or_torch_fns = [aten_ops_or_torch_fns]def decorator(func):for op in aten_ops_or_torch_fns:@functools.wraps(op)def wrapper(f, types, args, kwargs):return func(f, types, args, kwargs)MAP_TENSOR_ATEN_OP_TABLE[op] = wrapp... | 2 | 5 | 1 | 27 | 1 | 17 | 31 | 17 | null | ['aten_ops_or_torch_fns'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (implements) defined within the public class called public.The function start at line 17 and ends at 31. It contains 5 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 | no_dispatch | def no_dispatch():guard = torch._C._DisableTorchDispatch()try:yieldfinally:del guard | 2 | 6 | 0 | 20 | 1 | 35 | 40 | 35 | null | ['guard'] | None | null | 0 | 0 | 0 | null | 0 | null | The function (no_dispatch) defined within the public class called public.The function start at line 35 and ends at 40. It contains 6 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 | wrap_dim | def wrap_dim(i, dim):if i < 0:return dim + ireturn i | 2 | 4 | 2 | 18 | 0 | 43 | 46 | 43 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (wrap_dim) defined within the public class called public.The function start at line 43 and ends at 46. It contains 4 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [43.0] and does not return any value.. |
pytorch_ao | public | public | 0 | 0 | unwrap | def unwrap(t):if isinstance(t, MapTensor):with no_dispatch():return t.elemselse:return t | 2 | 6 | 1 | 26 | 0 | 49 | 54 | 49 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (unwrap) defined within the public class called public.The function start at line 49 and ends at 54. It contains 6 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 | unwrap_i | def unwrap_i(t, i):if isinstance(t, MapTensor):with no_dispatch():return t.elems[i]else:return t | 2 | 6 | 2 | 31 | 0 | 57 | 62 | 57 | null | [] | None | null | 0 | 0 | 0 | null | 0 | null | The function (unwrap_i) defined within the public class called public.The function start at line 57 and ends at 62. It contains 6 lines of code and it has a cyclomatic complexity of 2. It takes 2 parameters, represented as [57.0] and does not return any value.. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.