bayesianflow-for-chem 1.4.1__py3-none-any.whl → 1.4.2__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, EnsembleChemBFN
8
8
 
9
9
  __all__ = ["data", "tool", "train", "scorer", "ChemBFN", "MLP", "EnsembleChemBFN"]
10
- __version__ = "1.4.1"
10
+ __version__ = "1.4.2"
11
11
  __author__ = "Nianze A. Tao (Omozawa Sueno)"
@@ -54,9 +54,19 @@ class Linear(nn.Linear):
54
54
  :return:
55
55
  :rtype: None
56
56
  """
57
+ from torchao.dtypes.affine_quantized_tensor import AffineQuantizedTensor
58
+
57
59
  assert r > 0, "Rank should be larger than 0."
58
- self.lora_A = nn.Parameter(self.weight.new_zeros((r, self.in_features)))
59
- self.lora_B = nn.Parameter(self.weight.new_zeros((self.out_features, r)))
60
+ if isinstance(self.weight, AffineQuantizedTensor):
61
+ self.lora_A = nn.Parameter(
62
+ torch.zeros((r, self.in_features), device=self.weight.device)
63
+ )
64
+ self.lora_B = nn.Parameter(
65
+ torch.zeros((self.out_features, r), device=self.weight.device)
66
+ )
67
+ else:
68
+ self.lora_A = nn.Parameter(self.weight.new_zeros((r, self.in_features)))
69
+ self.lora_B = nn.Parameter(self.weight.new_zeros((self.out_features, r)))
60
70
  self.scaling = lora_alpha / r
61
71
  self.lora_dropout = lora_dropout
62
72
  self.lora_enabled = True
@@ -1207,23 +1217,23 @@ class EnsembleChemBFN(ChemBFN):
1207
1217
  )
1208
1218
 
1209
1219
  def quantise(
1210
- self, quantise_method: Optional[Callable[[ChemBFN], nn.Module]] = None
1220
+ self, quantise_method: Optional[Callable[[ChemBFN], None]] = None
1211
1221
  ) -> None:
1212
1222
  """
1213
1223
  Quantise the submodels. \n
1214
1224
  This method should be called, if necessary, before `torch.compile()`.
1215
1225
 
1216
- :param quantise_method: quantisation method; default is `bayesianflow_for_chem.tool.quantise_model`
1226
+ :param quantise_method: quantisation method; default is `bayesianflow_for_chem.tool.quantise_model_`
1217
1227
  :type quantise_method: callable | None
1218
1228
  :return:
1219
1229
  :rtype: None
1220
1230
  """
1221
1231
  if quantise_method is None:
1222
- from bayesianflow_for_chem.tool import quantise_model
1232
+ from bayesianflow_for_chem.tool import quantise_model_
1223
1233
 
1224
- quantise_method = quantise_model
1225
- for k, v in self.models.items():
1226
- self.models[k] = quantise_method(v)
1234
+ quantise_method = quantise_model_
1235
+ for _, v in self.models.items():
1236
+ quantise_method(v)
1227
1237
 
1228
1238
  def jit(self, freeze: bool = False) -> None:
1229
1239
  """
@@ -13,9 +13,8 @@ import torch
13
13
  import numpy as np
14
14
  import torch.nn as nn
15
15
  from torch import cuda, Tensor, softmax
16
- from torch.ao import quantization
17
16
  from torch.utils.data import DataLoader
18
- from typing_extensions import Self
17
+ from typing_extensions import Self, deprecated
19
18
  from rdkit.Chem import (
20
19
  rdDetermineBonds,
21
20
  GetFormalCharge,
@@ -386,6 +385,11 @@ def inpaint(
386
385
  ]
387
386
 
388
387
 
388
+ @deprecated(
389
+ "Eager mode quantization from `torch.ao` is deprecated and will be remove in version 2.10, "
390
+ "so this fuction will stop working since that time. "
391
+ "Please use `quantise_model_` instead."
392
+ )
389
393
  def quantise_model(model: ChemBFN) -> nn.Module:
390
394
  """
391
395
  Dynamic quantisation of the trained model to `torch.qint8` data type.
@@ -395,6 +399,7 @@ def quantise_model(model: ChemBFN) -> nn.Module:
395
399
  :return: quantised model
396
400
  :rtype: torch.nn.Module
397
401
  """
402
+ from torch.ao import quantization
398
403
  from torch.ao.nn.quantized import dynamic
399
404
  from torch.ao.nn.quantized.modules.utils import _quantize_weight
400
405
  from torch.ao.quantization.qconfig import default_dynamic_qconfig
@@ -527,6 +532,24 @@ def quantise_model(model: ChemBFN) -> nn.Module:
527
532
  return quantised_model
528
533
 
529
534
 
535
+ def quantise_model_(model: ChemBFN) -> None:
536
+ """
537
+ In-place dynamic quantisation of the trained model to `int8` data type. \n
538
+ Due to some limitations of `torchao` module, it is slower than method previded by `torch.ao`.
539
+
540
+ :param model: trained ChemBFN model
541
+ :type model: bayesianflow_for_chem.model.ChemBFN
542
+ :return:
543
+ :rtype: None
544
+ """
545
+ from torchao.quantization.quant_api import (
546
+ quantize_,
547
+ Int8DynamicActivationInt8WeightConfig,
548
+ )
549
+
550
+ quantize_(model, Int8DynamicActivationInt8WeightConfig())
551
+
552
+
530
553
  class GeometryConverter:
531
554
  """
532
555
  Converting between different 2D/3D molecular representations.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bayesianflow_for_chem
3
- Version: 1.4.1
3
+ Version: 1.4.2
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
@@ -23,6 +23,7 @@ Description-Content-Type: text/markdown
23
23
  License-File: LICENSE
24
24
  Requires-Dist: rdkit>=2023.9.6
25
25
  Requires-Dist: torch>=2.3.1
26
+ Requires-Dist: torchao>=0.12
26
27
  Requires-Dist: numpy>=1.26.4
27
28
  Requires-Dist: loralib>=0.1.2
28
29
  Requires-Dist: lightning>=2.2.0
@@ -0,0 +1,12 @@
1
+ bayesianflow_for_chem/__init__.py,sha256=IeIasLe6wLuGbH7DIlB38ehDPqvlMBT388hf58I3J30,329
2
+ bayesianflow_for_chem/data.py,sha256=WoOCOVmJX4WeHa2WeO4i66J2FS8rvRaYRCdlBN7ZeOM,6576
3
+ bayesianflow_for_chem/model.py,sha256=6pxGuIM7rKyawcz2hI8dT88rv3qFsnCvlLhDj1CB9YU,50595
4
+ bayesianflow_for_chem/scorer.py,sha256=7G1TVSwC0qONtNm6kiDZUWwvuFPzasNSjp4eJAk5TL0,4101
5
+ bayesianflow_for_chem/tool.py,sha256=Ne_ew1P8r6KWOqUZpb-BL_q7Dm6fnSTtxhJvgV1JHHs,26264
6
+ bayesianflow_for_chem/train.py,sha256=hGKyhGhLch-exSYPZdLXrLn3gf39Q1VLSJs2qtuikQE,9709
7
+ bayesianflow_for_chem/vocab.txt,sha256=HgtAZmpWYk4y8PqEVC4vqut1vE75DfRKE_10s2UW0rU,790
8
+ bayesianflow_for_chem-1.4.2.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
9
+ bayesianflow_for_chem-1.4.2.dist-info/METADATA,sha256=s6k85HFXvasxvZBJD3Rj8cFNJXehS-utcMeKC6tP8F8,5673
10
+ bayesianflow_for_chem-1.4.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
+ bayesianflow_for_chem-1.4.2.dist-info/top_level.txt,sha256=KHsanI3BMCt8D9Qpze2ycrF6nMa3PyojgO6eS1c8kco,22
12
+ bayesianflow_for_chem-1.4.2.dist-info/RECORD,,
@@ -1,12 +0,0 @@
1
- bayesianflow_for_chem/__init__.py,sha256=N_7P9Ea0eUmdC0wQKXIHiuMzPK4p9_cBF_YOexjo5yo,329
2
- bayesianflow_for_chem/data.py,sha256=WoOCOVmJX4WeHa2WeO4i66J2FS8rvRaYRCdlBN7ZeOM,6576
3
- bayesianflow_for_chem/model.py,sha256=zJkcUnZcxFa4iTo9_-BHzAM1MkJm1pbEGiczVgyUcxo,50186
4
- bayesianflow_for_chem/scorer.py,sha256=7G1TVSwC0qONtNm6kiDZUWwvuFPzasNSjp4eJAk5TL0,4101
5
- bayesianflow_for_chem/tool.py,sha256=Ma4dEBWP5GFKk-Tj5vBJgxGs_WAp4F87-b1UcsqUAn4,25486
6
- bayesianflow_for_chem/train.py,sha256=hGKyhGhLch-exSYPZdLXrLn3gf39Q1VLSJs2qtuikQE,9709
7
- bayesianflow_for_chem/vocab.txt,sha256=HgtAZmpWYk4y8PqEVC4vqut1vE75DfRKE_10s2UW0rU,790
8
- bayesianflow_for_chem-1.4.1.dist-info/licenses/LICENSE,sha256=hIahDEOTzuHCU5J2nd07LWwkLW7Hko4UFO__ffsvB-8,34523
9
- bayesianflow_for_chem-1.4.1.dist-info/METADATA,sha256=460yUOjHG9PTavIddJJ2Ufdq0bkLBZqbmMugyq6LVPQ,5643
10
- bayesianflow_for_chem-1.4.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
11
- bayesianflow_for_chem-1.4.1.dist-info/top_level.txt,sha256=KHsanI3BMCt8D9Qpze2ycrF6nMa3PyojgO6eS1c8kco,22
12
- bayesianflow_for_chem-1.4.1.dist-info/RECORD,,