{ "schema": "qfs.upstream-code-audit.v1", "upstream": { "repository": "moonshotai/Kimi-K2.7-Code", "revision": "74797c9c62378b951a1f6fcf5c4631024e9b8bef" }, "executed_during_audit": false, "weights_downloaded": false, "files": [ { "file": "configuration_deepseek.py", "sha256": "c1327c307e2dd11d1bf0adc8bcef69ae51f9617a3a869a9497bb08aec912f931", "bytes": 10615, "imports": [ { "line": 3, "statement": "from transformers.configuration_utils import PretrainedConfig" }, { "line": 4, "statement": "from transformers.utils import logging" } ], "effect_related_calls": [], "top_level_nodes": [ { "line": 6, "code": "logger = logging.get_logger(__name__)" }, { "line": 8, "code": "DEEPSEEK_PRETRAINED_CONFIG_ARCHIVE_MAP = {}" } ] }, { "file": "configuration_kimi_k25.py", "sha256": "2bc5487efced291e0e6aa3b24aad1082bade4172aff94ea1b6f0ae20a1d6bb4f", "bytes": 5435, "imports": [ { "line": 1, "statement": "from transformers.configuration_utils import PretrainedConfig" }, { "line": 4, "statement": "from configuration_deepseek import DeepseekV3Config" }, { "line": 6, "statement": "from .configuration_deepseek import DeepseekV3Config" } ], "effect_related_calls": [], "top_level_nodes": [ { "line": 3, "code": "try:\n from configuration_deepseek import DeepseekV3Config\nexcept ImportError:\n from .configuration_deepseek import DeepseekV3Config" } ] }, { "file": "kimi_k25_processor.py", "sha256": "537d7a708e1654766fc628c99667bdb9364136d3541633d6522ac43cef9bfea0", "bytes": 6906, "imports": [ { "line": 1, "statement": "from transformers.feature_extraction_utils import BatchFeature" }, { "line": 2, "statement": "from transformers.processing_utils import ProcessorMixin" }, { "line": 3, "statement": "from transformers.utils import logging" } ], "effect_related_calls": [], "top_level_nodes": [ { "line": 5, "code": "logger = logging.get_logger(__name__)" } ] }, { "file": "kimi_k25_vision_processing.py", "sha256": "498e20753c9aa6b6224ddbcd05b04deb7e987b76595bf5c28ee8583f33ebc375", "bytes": 10019, "imports": [ { "line": 4, "statement": "import json" }, { "line": 5, "statement": "from typing import Any, Dict, Optional, Union" }, { "line": 7, "statement": "import numpy as np" }, { "line": 8, "statement": "import torch" }, { "line": 9, "statement": "from PIL import Image" }, { "line": 10, "statement": "from transformers.image_processing_utils import BaseImageProcessor, BatchFeature" }, { "line": 12, "statement": "from transformers.utils import TensorType" }, { "line": 14, "statement": "from .media_utils import MediaInput, VideoChunkInput, _to_tensor, ensure_media_type, get_video_meta, image_to_np, navit_patchify, navit_resize_image, navit_resize_video, normalize, real_sample_fps_and_max_num_frames, timestamp_as_str" }, { "line": 21, "statement": "from mecord import VideoReader" } ], "effect_related_calls": [ { "line": 242, "call": "config_dict.copy" } ], "top_level_nodes": [ { "line": 1, "code": "'Image processor class for Kimi-K2.5.\\n'" }, { "line": 20, "code": "try:\n from mecord import VideoReader\nexcept ImportError:\n VideoReader = None" } ] }, { "file": "media_utils.py", "sha256": "77a6b1fed3580b0562443092928a0240c2989e3950377e93893952123ae48e3d", "bytes": 13179, "imports": [ { "line": 1, "statement": "import base64" }, { "line": 2, "statement": "import io" }, { "line": 3, "statement": "import math" }, { "line": 4, "statement": "import os" }, { "line": 5, "statement": "from datetime import datetime, timezone" }, { "line": 6, "statement": "from typing import List, Literal, Optional, TypedDict" }, { "line": 8, "statement": "import numpy as np" }, { "line": 9, "statement": "from PIL import Image" }, { "line": 10, "statement": "from pydantic import BaseModel, Field" }, { "line": 13, "statement": "from mecord import VideoReader" }, { "line": 353, "statement": "import torch" } ], "effect_related_calls": [ { "line": 196, "call": "Image.open(io.BytesIO(base64.b64decode(raw_base64))).convert" }, { "line": 199, "call": "Image.open(data).convert" }, { "line": 201, "call": "Image.open(io.BytesIO(data)).convert" }, { "line": 196, "call": "Image.open" }, { "line": 199, "call": "Image.open" }, { "line": 201, "call": "Image.open" } ], "top_level_nodes": [ { "line": 12, "code": "try:\n from mecord import VideoReader\nexcept ImportError:\n VideoReader = None" }, { "line": 41, "code": "MediaInput = ImageInput | VideoChunkInput" } ] }, { "file": "modeling_deepseek.py", "sha256": "17e079e0a5e41114aabd2ae5ba924128ba6652bc6f9a00ea06efcd1230340406", "bytes": 78639, "imports": [ { "line": 21, "statement": "import math" }, { "line": 22, "statement": "import warnings" }, { "line": 23, "statement": "from typing import List, Optional, Tuple, Union" }, { "line": 25, "statement": "import numpy as np" }, { "line": 26, "statement": "import torch" }, { "line": 27, "statement": "import torch.distributed as dist" }, { "line": 28, "statement": "import torch.nn.functional as F" }, { "line": 29, "statement": "import torch.utils.checkpoint" }, { "line": 30, "statement": "from torch import nn" }, { "line": 31, "statement": "from torch.nn import BCEWithLogitsLoss, CrossEntropyLoss, MSELoss" }, { "line": 32, "statement": "from transformers.activations import ACT2FN" }, { "line": 33, "statement": "from transformers.cache_utils import Cache, DynamicCache" }, { "line": 34, "statement": "from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask" }, { "line": 36, "statement": "from transformers.modeling_outputs import BaseModelOutputWithPast, CausalLMOutputWithPast, SequenceClassifierOutputWithPast" }, { "line": 39, "statement": "from transformers.modeling_utils import PreTrainedModel" }, { "line": 40, "statement": "from transformers.pytorch_utils import ALL_LAYERNORM_LAYERS, is_torch_greater_or_equal_than_1_13" }, { "line": 42, "statement": "from transformers.utils import add_start_docstrings, add_start_docstrings_to_model_forward, is_flash_attn_2_available, is_flash_attn_greater_or_equal_2_10, logging, replace_return_docstrings" }, { "line": 56, "statement": "from .configuration_deepseek import DeepseekV3Config" }, { "line": 49, "statement": "from transformers.utils.import_utils import is_torch_fx_available" }, { "line": 59, "statement": "from flash_attn import flash_attn_func, flash_attn_varlen_func" }, { "line": 60, "statement": "from flash_attn.bert_padding import pad_input" }, { "line": 61, "statement": "from flash_attn.bert_padding import index_first_axis, unpad_input" }, { "line": 67, "statement": "import torch.fx" }, { "line": 444, "statement": "import torch.nn.init as init" } ], "effect_related_calls": [], "top_level_nodes": [ { "line": 20, "code": "' PyTorch DeepSeek model.'" }, { "line": 48, "code": "try:\n from transformers.utils.import_utils import is_torch_fx_available\nexcept ImportError:\n\n def is_torch_fx_available() -> bool:\n return hasattr(torch, 'fx')" }, { "line": 58, "code": "if is_flash_attn_2_available():\n from flash_attn import flash_attn_func, flash_attn_varlen_func\n from flash_attn.bert_padding import pad_input\n from flash_attn.bert_padding import index_first_axis, unpad_input" }, { "line": 65, "code": "if is_torch_fx_available():\n if not is_torch_greater_or_equal_than_1_13:\n import torch.fx\n _prepare_4d_causal_attention_mask = torch.fx.wrap(_prepare_4d_causal_attention_mask)" }, { "line": 72, "code": "logger = logging.get_logger(__name__)" }, { "line": 74, "code": "_CONFIG_FOR_DOC = 'DeepseekV3Config'" }, { "line": 120, "code": "ALL_LAYERNORM_LAYERS.append(DeepseekV3RMSNorm)" }, { "line": 1135, "code": "ATTENTION_CLASSES = {'eager': DeepseekV3Attention, 'flash_attention_2': DeepseekV3FlashAttention2}" }, { "line": 1222, "code": "DeepseekV3_START_DOCSTRING = '\\n This model inherits from [`PreTrainedModel`]. Check the superclass documentation for the generic methods the\\n library implements for all its model (such as downloading or saving, resizing the input embeddings, pruning heads\\n etc.)\\n\\n This model is also a PyTorch [torch.nn.Module](https://pytorch.org/docs/stable/nn.html#torch.nn.Module) subclass.\\n Use it as a regular PyTorch Module and refer to the PyTorch documentation for all matter related to general usage\\n and behavior.\\n\\n Parameters:\\n config ([`DeepseekV3Config`]):\\n Model configuration class with all the parameters of the model. Initializing with a config file does not\\n load the weights associated with the model, only the configuration. Check out the\\n [`~PreTrainedModel.from_pretrained`] method to load the model weights.\\n'" }, { "line": 1264, "code": "DeepseekV3_INPUTS_DOCSTRING = \"\\n Args:\\n input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):\\n Indices of input sequence tokens in the vocabulary. Padding will be ignored by default should you provide\\n it.\\n\\n Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and\\n [`PreTrainedTokenizer.__call__`] for details.\\n\\n [What are input IDs?](../glossary#input-ids)\\n attention_mask (`torch.Tensor` of shape `(batch_size, sequence_length)`, *optional*):\\n Mask to avoid performing attention on padding token indices. Mask values selected in `[0, 1]`:\\n\\n - 1 for tokens that are **not masked**,\\n - 0 for tokens that are **masked**.\\n\\n [What are attention masks?](../glossary#attention-mask)\\n\\n Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and\\n [`PreTrainedTokenizer.__call__`] for details.\\n\\n If `past_key_values` is used, optionally only the last `input_ids` have to be input (see\\n `past_key_values`).\\n\\n If you want to change padding behavior, you should read [`modeling_opt._prepare_decoder_attention_mask`]\\n and modify to your needs. See diagram 1 in [the paper](https://arxiv.org/abs/1910.13461) for more\\n information on the default strategy.\\n\\n - 1 indicates the head is **not masked**,\\n - 0 indicates the head is **masked**.\\n position_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`, *optional*):\\n Indices of positions of each input sequence tokens in the position embeddings. Selected in the range `[0,\\n config.n_positions - 1]`.\\n\\n [What are position IDs?](../glossary#position-ids)\\n past_key_values (`Cache` or `tuple(tuple(torch.FloatTensor))`, *optional*):\\n Pre-computed hidden-states (key and values in the self-attention blocks and in the cross-attention\\n blocks) that can be used to speed up sequential decoding. This typically consists in the `past_key_values`\\n returned by the model at a previous stage of decoding, when `use_cache=True` or `config.use_cache=True`.\\n\\n Two formats are allowed:\\n - a [`~cache_utils.Cache`] instance;\\n - Tuple of `tuple(torch.FloatTensor)` of length `config.n_layers`, with each tuple having 2 tensors of\\n shape `(batch_size, num_heads, sequence_length, embed_size_per_head)`). This is also known as the legacy\\n cache format.\\n\\n The model will output the same cache format that is fed as input. If no `past_key_values` are passed, the\\n legacy cache format will be returned.\\n\\n If `past_key_values` are used, the user can optionally input only the last `input_ids` (those that don't\\n have their past key value states given to this model) of shape `(batch_size, 1)` instead of all `input_ids`\\n of shape `(batch_size, sequence_length)`.\\n inputs_embeds (`torch.FloatTensor` of shape `(batch_size, sequence_length, hidden_size)`, *optional*):\\n Optionally, instead of passing `input_ids` you can choose to directly pass an embedded representation. This\\n is useful if you want more control over how to convert `input_ids` indices into associated vectors than the\\n model's internal embedding lookup matrix.\\n use_cache (`bool`, *optional*):\\n If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding (see\\n `past_key_values`).\\n output_attentions (`bool`, *optional*):\\n Whether or not to return the attentions tensors of all attention layers. See `attentions` under returned\\n tensors for more detail.\\n output_hidden_states (`bool`, *optional*):\\n Whether or not to return the hidden states of all layers. See `hidden_states` under returned tensors for\\n more detail.\\n return_dict (`bool`, *optional*):\\n Whether or not to return a [`~utils.ModelOutput`] instead of a plain tuple.\\n\"" } ] }, { "file": "modeling_kimi_k25.py", "sha256": "a1594f129ae8dc5fa3c9dbbc24e8e603b30d7caef1226669b4d95dc8f2a3e2dd", "bytes": 53045, "imports": [ { "line": 41, "statement": "import math" }, { "line": 42, "statement": "from collections.abc import Sequence" }, { "line": 43, "statement": "from copy import deepcopy" }, { "line": 44, "statement": "from typing import Optional" }, { "line": 46, "statement": "import numpy as np" }, { "line": 47, "statement": "import torch" }, { "line": 48, "statement": "import torch.nn as nn" }, { "line": 49, "statement": "import torch.nn.functional as F" }, { "line": 50, "statement": "from transformers import activations" }, { "line": 58, "statement": "from transformers.activations import PytorchGELUTanh" }, { "line": 59, "statement": "from transformers.cache_utils import Cache" }, { "line": 60, "statement": "from transformers.configuration_utils import PretrainedConfig" }, { "line": 61, "statement": "from transformers.modeling_utils import PreTrainedModel" }, { "line": 62, "statement": "from transformers.models.llava.modeling_llava import LlavaCausalLMOutputWithPast" }, { "line": 64, "statement": "from transformers.utils import is_flash_attn_2_available" }, { "line": 66, "statement": "from .configuration_kimi_k25 import KimiK25Config" }, { "line": 67, "statement": "from .modeling_deepseek import DeepseekV3ForCausalLM" }, { "line": 53, "statement": "from transformers.activations import PytorchGELUTanh" }, { "line": 71, "statement": "from flash_attn import flash_attn_varlen_func" }, { "line": 55, "statement": "from transformers.activations import GELUTanh" } ], "effect_related_calls": [ { "line": 678, "call": "deepcopy" } ], "top_level_nodes": [ { "line": 52, "code": "try:\n from transformers.activations import PytorchGELUTanh\nexcept ImportError:\n from transformers.activations import GELUTanh\n activations.PytorchGELUTanh = GELUTanh\n PytorchGELUTanh = GELUTanh" }, { "line": 70, "code": "if is_flash_attn_2_available():\n from flash_attn import flash_attn_varlen_func\nelse:\n flash_attn_varlen_func = None" }, { "line": 152, "code": "VL_VISION_ATTENTION_FUNCTIONS = {'flash_attention_2': multihead_attention, 'eager': eager_attention}" } ] }, { "file": "tokenization_kimi.py", "sha256": "88394687bd081f55928849b2d140e190c70297660d3fb8b7c54c0e5633b177e3", "bytes": 14132, "imports": [ { "line": 1, "statement": "import os" }, { "line": 2, "statement": "from collections import OrderedDict" }, { "line": 3, "statement": "from logging import getLogger" }, { "line": 4, "statement": "from pathlib import Path" }, { "line": 5, "statement": "from shutil import copyfile" }, { "line": 6, "statement": "from typing import Any, Dict, Iterator, List, Optional, Tuple, Union, cast" }, { "line": 8, "statement": "import tiktoken" }, { "line": 9, "statement": "from tiktoken.load import load_tiktoken_bpe" }, { "line": 10, "statement": "from tokenizers import AddedToken" }, { "line": 11, "statement": "from transformers.convert_slow_tokenizer import bytes_to_unicode" }, { "line": 12, "statement": "from transformers.tokenization_utils import PreTrainedTokenizer" }, { "line": 14, "statement": "from .tool_declaration_ts import encode_tools_to_typescript_style" } ], "effect_related_calls": [ { "line": 106, "call": "load_tiktoken_bpe" }, { "line": 319, "call": "copyfile" } ], "top_level_nodes": [ { "line": 16, "code": "logger = getLogger(__name__)" }, { "line": 17, "code": "VOCAB_FILES_NAMES = {'vocab_file': 'tiktoken.model'}" } ] }, { "file": "tool_declaration_ts.py", "sha256": "97e09ed262f1cd38f87584eaa46c5d4d5b3c9725dd299b21642f389040794ebc", "bytes": 16517, "imports": [ { "line": 4, "statement": "import dataclasses" }, { "line": 5, "statement": "import json" }, { "line": 6, "statement": "import logging" }, { "line": 7, "statement": "from collections.abc import Sequence" }, { "line": 8, "statement": "from typing import Any" } ], "effect_related_calls": [ { "line": 409, "call": "definitions_copy.items" }, { "line": 463, "call": "_openai_function_to_typescript_style" } ], "top_level_nodes": [ { "line": 1, "code": "'\\nEncode structured tool declaration to typescript style string.\\n'" }, { "line": 10, "code": "logger = logging.getLogger(__name__)" }, { "line": 12, "code": "_TS_INDENT = ' '" }, { "line": 13, "code": "_TS_FIELD_DELIMITER = ',\\n'" }, { "line": 308, "code": "_ParameterType = _ParameterTypeScalar | _ParameterTypeObject | _ParameterTypeArray | _ParameterTypeEnum | _ParameterTypeAnyOf | _ParameterTypeUnion | _ParameterTypeRef" } ] } ], "license": "Modified MIT, retained upstream/LICENSE; native runtime is Apache-2.0 Transformers 5.16.1", "import_time_effects": [ "Imports Python/NumPy/Torch/Transformers; upstream K3 hard imports FLA and imports/registry-mutates ACT2FN and ALL_LAYERNORM_LAYERS.", "Upstream processor/tokenizer closure is not used by fixture: byte tokenizer is authored independently. tiktoken load_tiktoken_bpe can read local or remote vocabulary at tokenizer construction. media_utils reads image filenames/data on explicit invocation, not import.", "No subprocess, shell, eval/exec, socket, network request, or model-weight load found in upstream module import-time statements. Decorators and dependency imports execute library initialization. This is source review, not sandboxing." ], "runtime_scope": "Native installed Transformers Kimi_K25 complete wrapper, no upstream remote Python execution.", "network_policy": "No upstream model weights fetched. Custom capture explicitly permits pinned code metadata/download from the selected private model repo; local model weights. Not entirely offline capture. Comparison independent of code and GPU.", "patch_provenance": null, "review_limitations": "Static source review is not a security guarantee. Dependency implementations belong to the pinned environment. Main must run all runtime checks before release." }