Upload HfMoondream
Browse files- config.py +1 -1
- layers.py +9 -2
- model.safetensors +2 -2
config.py
CHANGED
|
@@ -38,7 +38,7 @@ class RegionConfig:
|
|
| 38 |
size_feat_dim: int = 512
|
| 39 |
size_out_dim: int = 2048
|
| 40 |
inner_dim: int = 8192
|
| 41 |
-
group_size: Optional[int] =
|
| 42 |
|
| 43 |
@dataclass(frozen=True)
|
| 44 |
class TokenizerConfig:
|
|
|
|
| 38 |
size_feat_dim: int = 512
|
| 39 |
size_out_dim: int = 2048
|
| 40 |
inner_dim: int = 8192
|
| 41 |
+
group_size: Optional[int] = None
|
| 42 |
|
| 43 |
@dataclass(frozen=True)
|
| 44 |
class TokenizerConfig:
|
layers.py
CHANGED
|
@@ -7,8 +7,6 @@ from typing import Literal
|
|
| 7 |
from torchao import quantize_
|
| 8 |
from torchao.quantization import int4_weight_only
|
| 9 |
|
| 10 |
-
from .packing import dequantize_tensor
|
| 11 |
-
|
| 12 |
|
| 13 |
def gelu_approx(x):
|
| 14 |
return F.gelu(x, approximate="tanh")
|
|
@@ -24,6 +22,15 @@ def linear(x: torch.Tensor, w: LinearWeights) -> torch.Tensor:
|
|
| 24 |
return F.linear(x, w.weight, w.bias)
|
| 25 |
|
| 26 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
class QuantizedLinear(nn.Module):
|
| 28 |
def __init__(
|
| 29 |
self,
|
|
|
|
| 7 |
from torchao import quantize_
|
| 8 |
from torchao.quantization import int4_weight_only
|
| 9 |
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def gelu_approx(x):
|
| 12 |
return F.gelu(x, approximate="tanh")
|
|
|
|
| 22 |
return F.linear(x, w.weight, w.bias)
|
| 23 |
|
| 24 |
|
| 25 |
+
def dequantize_tensor(W_q, scale, zero, orig_shape, dtype=torch.bfloat16):
|
| 26 |
+
_step = W_q.shape[0]
|
| 27 |
+
W_r = torch.empty([2 * _step, W_q.shape[1]], dtype=dtype, device=W_q.device)
|
| 28 |
+
W_r[:_step] = (W_q & 0b11110000) >> 4
|
| 29 |
+
W_r[_step:] = W_q & 0b00001111
|
| 30 |
+
W_r.sub_(zero).mul_(scale)
|
| 31 |
+
return W_r.reshape(orig_shape)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
class QuantizedLinear(nn.Module):
|
| 35 |
def __init__(
|
| 36 |
self,
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
-
size
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:de670ae0501f95abc4b15669d80da1551cb5ec66ce80bbae0fb290c212d5eb95
|
| 3 |
+
size 2119003880
|