Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions graph_net/tensor_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,14 @@ def _get_limited_precision_float_str(self, value):
return value
if math.isnan(value) or math.isinf(value):
return f'float("{value}")'
return f"{value:.3f}"
return f"{value:.6f}"

def _format_data(self, data):
if data is None:
return "None"
elif isinstance(data, list):
return "[{}]".format(
", ".join(f"{x:.6f}" if isinstance(x, float) else str(x) for x in data)
", ".join(self._get_limited_precision_float_str(x) for x in data)
)
else:
return repr(data)
Expand Down
21 changes: 7 additions & 14 deletions graph_net/torch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,9 @@ def apply_templates(forward_code: str) -> str:
def get_limited_precision_float_str(value):
if not isinstance(value, float):
return value
if math.isnan(value):
return "float('nan')"
if math.isinf(value):
return "float('inf')" if value > 0 else "float('-inf')"
return f"{value:.3f}"
if math.isnan(value) or math.isinf(value):
return f'float("{value}")'
return f"{value:.6f}"


def convert_state_and_inputs_impl(state_dict, example_inputs):
Expand Down Expand Up @@ -130,16 +128,11 @@ def format_data(data):
return "None"
elif isinstance(data, torch.Tensor):
if data.dtype.is_floating_point:

def float_to_str(x):
if math.isinf(x):
return "float('inf')" if x > 0 else "float('-inf')"
if math.isnan(x):
return "float('nan')"
return f"{x:.6f}"

return "[{}]".format(
", ".join(float_to_str(x) for x in data.flatten().tolist())
", ".join(
get_limited_precision_float_str(x)
for x in data.flatten().tolist()
)
)
else:
return "[{}]".format(", ".join(f"{x}" for x in data.flatten().tolist()))
Expand Down
Loading