| 152 | self._set_vocab_gpt2() |
| 153 | |
| 154 | def get_tensors(self) -> Iterator[tuple[str, Tensor]]: |
| 155 | for part_name in self.part_names: |
| 156 | logger.info(f"gguf: loading model part '{part_name}'") |
| 157 | ctx: ContextManager[Any] |
| 158 | if self.is_safetensors: |
| 159 | from safetensors import safe_open |
| 160 | ctx = cast(ContextManager[Any], safe_open(self.dir_model / part_name, framework="pt", device="cpu")) |
| 161 | else: |
| 162 | ctx = contextlib.nullcontext(torch.load(str(self.dir_model / part_name), map_location="cpu", mmap=True, weights_only=True)) |
| 163 | |
| 164 | with ctx as model_part: |
| 165 | for name in model_part.keys(): |
| 166 | data = model_part.get_tensor(name) if self.is_safetensors else model_part[name] |
| 167 | yield name, data |
| 168 | |
| 169 | def match_model_tensor_name(self, name: str, key: gguf.MODEL_TENSOR, bid: int | None, suffix: str = ".weight") -> bool: |
| 170 | if key not in gguf.MODEL_TENSORS[self.model_arch]: |