bayesianflow-for-chem 1.2.5__py3-none-any.whl → 1.2.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bayesianflow-for-chem might be problematic. Click here for more details.

@@ -7,5 +7,5 @@ from . import data, tool, train, scorer
7
7
  from .model import ChemBFN, MLP
8
8
 
9
9
  __all__ = ["data", "tool", "train", "scorer", "ChemBFN", "MLP"]
10
- __version__ = "1.2.5"
10
+ __version__ = "1.2.6"
11
11
  __author__ = "Nianze A. Tao (Omozawa Sueno)"
@@ -492,15 +492,16 @@ def inpaint(
492
492
 
493
493
  def quantise_model(model: ChemBFN) -> nn.Module:
494
494
  """
495
- Dynamic quantisation of the trained model.
495
+ Dynamic quantisation of the trained model to `torch.qint8` data type.
496
496
 
497
497
  :param model: trained ChemBFN model
498
498
  :type model: bayesianflow_for_chem.model.ChemBFN
499
499
  :return: quantised model
500
500
  :rtype: torch.nn.Module
501
501
  """
502
- from torch.ao.nn.quantized.modules.utils import _quantize_weight
503
502
  from torch.ao.nn.quantized import dynamic
503
+ from torch.ao.nn.quantized.modules.utils import _quantize_weight
504
+ from torch.ao.quantization.qconfig import default_dynamic_qconfig
504
505
 
505
506
  class QuantisedLinear(dynamic.Linear):
506
507
  # Modified from https://github.com/pytorch/pytorch/blob/main/torch/ao/nn/quantized/dynamic/modules/linear.py
@@ -543,7 +544,22 @@ def quantise_model(model: ChemBFN) -> nn.Module:
543
544
  self._packed_params.requires_grad_(False)
544
545
 
545
546
  def forward(self, x: Tensor) -> Tensor:
546
- result = dynamic.Linear.forward(self, x)
547
+ if self._packed_params.dtype == torch.qint8:
548
+ if self.version is None or self.version < 4:
549
+ Y = torch.ops.quantized.linear_dynamic(
550
+ x, self._packed_params._packed_params
551
+ )
552
+ else:
553
+ Y = torch.ops.quantized.linear_dynamic(
554
+ x, self._packed_params._packed_params, reduce_range=True
555
+ )
556
+ elif self._packed_params.dtype == torch.float16:
557
+ Y = torch.ops.quantized.linear_dynamic_fp16(
558
+ x, self._packed_params._packed_params
559
+ )
560
+ else:
561
+ raise RuntimeError("Unsupported dtype on dynamic quantized linear!")
562
+ result = Y.to(x.dtype)
547
563
  if self.lora_enabled and isinstance(self.lora_dropout, float):
548
564
  result += (
549
565
  nn.functional.dropout(x, self.lora_dropout, self.training)
@@ -562,11 +578,6 @@ def quantise_model(model: ChemBFN) -> nn.Module:
562
578
  if mod.qconfig is not None and mod.qconfig.weight is not None:
563
579
  weight_observer = mod.qconfig.weight()
564
580
  else:
565
- # We have the circular import issues if we import the qconfig in the beginning of this file:
566
- # https://github.com/pytorch/pytorch/pull/24231. The current workaround is to postpone the
567
- # import until we need it.
568
- from torch.ao.quantization.qconfig import default_dynamic_qconfig
569
-
570
581
  weight_observer = default_dynamic_qconfig.weight()
571
582
  dtype = weight_observer.dtype
572
583
  assert dtype in [torch.qint8, torch.float16], (
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: bayesianflow_for_chem
3
- Version: 1.2.5
3
+ Version: 1.2.6
4
4
  Summary: Bayesian flow network framework for Chemistry
5
5
  Home-page: https://augus1999.github.io/bayesian-flow-network-for-chemistry/
6
6
  Author: Nianze A. Tao
@@ -1,12 +1,12 @@
1
- bayesianflow_for_chem/__init__.py,sha256=GMGe5nU963qFL6vJ9OZSfqfSyEImC_P2zyUS0cyP3Mg,293
1
+ bayesianflow_for_chem/__init__.py,sha256=sdyCK-Zd32-FNOcjuSB02ABx8vn53phorQeVqyWMWk4,293
2
2
  bayesianflow_for_chem/data.py,sha256=9tpRba40lxwrB6aPSJMkxUglEVC3VEQC9wWxhDuz3Q8,7760
3
3
  bayesianflow_for_chem/model.py,sha256=HvEvW_xRbkv4eSv5lhd72BJMZkg-ZACEi1DAW3p5Q1Y,35918
4
4
  bayesianflow_for_chem/scorer.py,sha256=mV1vX8aBGFra2BE7N8WHihVIo3dXmUdPQIGfSaiuNdk,4084
5
- bayesianflow_for_chem/tool.py,sha256=tJjb8q3_orNkj2BYJwz5VxqeaOv55dvqO93_uigLJIk,23221
5
+ bayesianflow_for_chem/tool.py,sha256=VuEqbT7Qraa4vnKMHbToyAYIiRoQI7gEPLKEBCWGmVg,23706
6
6
  bayesianflow_for_chem/train.py,sha256=kj6icGqymUUYopDtpre1oE_wpvpeNilbpzgffBsd1tk,9589
7
7
  bayesianflow_for_chem/vocab.txt,sha256=HgtAZmpWYk4y8PqEVC4vqut1vE75DfRKE_10s2UW0rU,790
8
- bayesianflow_for_chem-1.2.5.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
9
- bayesianflow_for_chem-1.2.5.dist-info/METADATA,sha256=hwEEDW6ipmHpjRjQDKxWk5zqI9jwjsl-yxBpvYn93HQ,5890
10
- bayesianflow_for_chem-1.2.5.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
11
- bayesianflow_for_chem-1.2.5.dist-info/top_level.txt,sha256=KHsanI3BMCt8D9Qpze2ycrF6nMa3PyojgO6eS1c8kco,22
12
- bayesianflow_for_chem-1.2.5.dist-info/RECORD,,
8
+ bayesianflow_for_chem-1.2.6.dist-info/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
9
+ bayesianflow_for_chem-1.2.6.dist-info/METADATA,sha256=Akoh5dQW_0jeYuGC4ZKKYHS1WJn0xRwGDr7ut-Q-5sc,5890
10
+ bayesianflow_for_chem-1.2.6.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
11
+ bayesianflow_for_chem-1.2.6.dist-info/top_level.txt,sha256=KHsanI3BMCt8D9Qpze2ycrF6nMa3PyojgO6eS1c8kco,22
12
+ bayesianflow_for_chem-1.2.6.dist-info/RECORD,,