Skip to content

Commit

Permalink
Fix tutorials (#1168)
Browse files Browse the repository at this point in the history
* fix xquant wrong assumption that max cut was always computed

* replace dataset in keras tutorial to be numpy arrays

* limit hugging face version in yolov8n notebook

* fix bug with model count params in pytorch pruning tutorial

---------

Co-authored-by: reuvenp <[email protected]>
  • Loading branch information
reuvenperetz and reuvenp authored Aug 14, 2024
1 parent 37929e0 commit 73f5fab
Show file tree
Hide file tree
Showing 9 changed files with 2,568 additions and 2,542 deletions.
10 changes: 6 additions & 4 deletions model_compression_toolkit/xquant/common/tensorboard_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,14 @@ def add_text_information(self,
similarity_metrics (Dict[str, Dict[str, float]]): A dictionary containing similarity metrics between quantized and float models for both representative and validation datasets.
quantized_model_metadata (Dict): Metadata from the quantized model.
"""
# Add the computed max cut
maxcut_str = f"MaxCut: {quantized_model_metadata['scheduling_info'][MAX_CUT]}"
self.tb_writer.add_text(maxcut_str, MAX_CUT)

# Add output similarity between quantized and float models on representative and validation datasets
output_similarity_repr = f"Similarity Metrics on outputs using representative dataset: \n" + "\n".join([f"{key}: {value:.4f}" for key, value in similarity_metrics[OUTPUT_SIMILARITY_METRICS_REPR].items()])
output_similarity_val = f"Similarity Metrics on outputs using validation dataset: \n" + "\n".join([f"{key}: {value:.4f}" for key, value in similarity_metrics[OUTPUT_SIMILARITY_METRICS_VAL].items()])
self.tb_writer.add_text(output_similarity_repr, OUTPUT_SIMILARITY_METRICS_REPR)
self.tb_writer.add_text(output_similarity_val, OUTPUT_SIMILARITY_METRICS_VAL)

# Add the max cut if it was computed
if 'scheduling_info' in quantized_model_metadata:
maxcut_str = f"MaxCut: {quantized_model_metadata['scheduling_info'][MAX_CUT]}"
self.tb_writer.add_text(maxcut_str, MAX_CUT)

3 changes: 2 additions & 1 deletion model_compression_toolkit/xquant/keras/tensorboard_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ def get_graph_for_tensorboard_display(self,
# Read the quantized model into a graph structure.
quant_graph = model_reader(quantized_model)

insert_cut_info_into_graph(quant_graph, quantized_model_metadata)
if 'scheduling_info' in quantized_model_metadata:
insert_cut_info_into_graph(quant_graph, quantized_model_metadata)

# Iterate over each node in the graph.
for node in quant_graph.nodes:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ def get_graph_for_tensorboard_display(self,
to_tensor=self.fw_impl.to_tensor,
to_numpy=self.fw_impl.to_numpy)

insert_cut_info_into_graph(quant_graph, quantized_model_metadata, quantized_model)
if 'scheduling_info' in quantized_model_metadata:
insert_cut_info_into_graph(quant_graph, quantized_model_metadata, quantized_model)

# Iterate through each node in the graph
for node in quant_graph.nodes:
Expand Down
Loading

0 comments on commit 73f5fab

Please sign in to comment.