Add type annotations to all functions and methods in @qwen3moefused\quantize_gguf\** .…
- User
Add type annotations to all functions and methods in @qwen3_moe_fused\quantize_gguf** . Don't omit
-> None. --- Content from referenced files --- Content from @qwen3_moe_fused\quantize_gguf_init_.py:Content from @qwen3_moe_fused\quantize_gguf\layer.py: from typing import Optional
import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from gguf import dequantize
from ..modular_qwen3_moe_fused import MoeFusedLinear, moe_fused_linear
def gguf_dequantize(weight_data: torch.Tensor, tensor_type: int, shape: tuple) -> torch.Tensor: if weight_data.device.type != "cpu": data_np = weight_data.detach().cpu().numpy() else: data_np = weight_data.detach().numpy() w_np = dequantize(data_np, tensor_type) w_np = w_np.reshape(shape) return torch.from_numpy(w_np)
def reverse_permute_weights(weights: torch.Tensor, n_head: int, num_kv_heads: Optional[int] = None) -> torch.Tensor: if num_kv_heads is not None and n_head != num_kv_heads: n_head = num_kv_heads dim = weights.shape[0] // n_head // 2 w = weights.view(n_head, dim, 2, *weights.shape[1:]) return w.transpose(2, 1).reshape(weights.shape)
class GGUFEmbedding(nn.Module): def init(self, num_embeddings, embedding_dim, padding_idx=None, device=None, dtype=None): super().init() self.num_embeddings = num_embeddings self.embedding_dim = embedding_dim self.padding_idx = padding_idx self.register_buffer("weight", None) self.tensor_type = None self.original_shape = None self.compute_dtype = dtype
codedef forward(self, x): if self.tensor_type is None: if self.weight is not None and self.weight.is_floating_point(): return F.embedding(x, self.weight, self.padding_idx) raise RuntimeError("GGUFEmbedding not initialized with GGUF data") w = gguf_dequantize(self.weight, self.tensor_type, self.original_shape) dtype = self.compute_dtype if self.compute_dtype is not None else torch.get_default_dtype() w = w.to(device=x.device, dtype=dtype) if w.shape != (self.num_embeddings, self.embedding_dim): if w.shape == (self.embedding_dim, self.num_embeddings): w = w.t() else: if w.numel() == self.num_embeddings * self.embedding_dim: w = w.view(self.num_embeddings, self.embedding_dim) return F.embedding(x, w, self.padding_idx) Assistant
I will add type annotations to the files in
qwen3_moe_fused\quantize_gguf\.First, I will read the files to ensure I have the exact content for replacement.
Assistant
I will add type annotations to
qwen3_moe_fused\quantize_gguf\layer.py,qwen3_moe_fused\quantize_gguf\quantizer.pyandqwen3_moe_fused\quantize_gguf\utils.py.Assistant
I will verify the content of
qwen3_moe_fused\quantize_gguf\__init__.py.Assistant
I will run
ruff checkon theqwen3_moe_fused\quantize_ggufdirectory to ensure the changes are valid and adhere to linting standards.Assistant
I will use
ruffto automatically fix the linting errors, which includes removing unused imports and updating type annotations to use standard collection types.Assistant
I will read the files
qwen3_moe_fused\quantize_gguf\layer.py,qwen3_moe_fused\quantize_gguf\quantizer.py, andqwen3_moe_fused\quantize_gguf\utils.pyto verify the changes and ensures thatruffcorrectly applied the fixes.Assistant
I have added type annotations to all functions and methods in
@qwen3_moe_fused\quantize_gguf\**and verified the changes withruff.