Skip to content

Commit

Permalink
fix code style
Browse files Browse the repository at this point in the history
  • Loading branch information
bobcheng15 committed Jun 14, 2024
1 parent 0673d9f commit 1b52bcf
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions sam/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def safeCastScipyTensorToInts(tensor):
data[i] = round_sparse(tensor.data[i])
return scipy.sparse.coo_matrix(tensor.coords, data, tensor.shape)


def bfbin2float(bfstr):
sign = bfstr[0]
exp = bfstr[1:9]
Expand Down Expand Up @@ -91,7 +92,7 @@ def float2bfbin(fnum):
lfrac = "0" + fstr[9:16]
hfrac = fstr[16:]
# Enable rounding
if (hfrac[0] == "1" and (hfrac[1] == "1" or hfrac[2] == "1")) or (lfrac[7] == "1" and hfrac[0] == "1"):
if (hfrac[0] == "1" and (hfrac[1] == "1" or hfrac[2] == "1")) or (lfrac[7] == "1" and hfrac[0] == "1"):
# bit 8 of the float mantissa is set, so round up
if lfrac[1:8] == "1111111": # roll over mantissa and increase exp if needed
exp = "{:08b}".format((int(exp, 2) + 1)) # exp overflow?
Expand Down Expand Up @@ -360,6 +361,7 @@ def load(self, tensor, cast):
self.tensor = self.lastLoaded
return self.tensor


class InputCacheSparseML:
def __init__(self):
self.lastLoaded = None
Expand All @@ -378,6 +380,7 @@ def load(self, tensor, cast):
self.tensor = self.lastLoaded
return self.tensor


class FormatWriter:
def __init__(self, cast_int=True):
self.cast = cast_int
Expand Down Expand Up @@ -693,7 +696,8 @@ def __str__(self):

def load(self, loader):
return loader.load(self.path)



class SparseMLTensor:
def __init__(self, path):
self.path = path
Expand Down

0 comments on commit 1b52bcf

Please sign in to comment.