Skip to content

Commit

Permalink
cache representations
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasLoos committed Feb 24, 2024
1 parent 6ac5abd commit cc3c883
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ <h1 style="text-align: center;">H-Space similarity explorer</h1>
let current_model = null;
let available_positions = {};
let current_position = 'mid_block'; // assuming mid_block is always available
const repr_cache = {};
const available_concepts = [];
const concepts = [];
const initial_concepts = [
Expand Down Expand Up @@ -172,13 +173,20 @@ <h1 style="text-align: center;">H-Space similarity explorer</h1>

// helper function to load the representation
const getRepr = () => {
const url = `representations/${current_model.short}/${concept.name}/repr-${current_position}.bin`;
if (repr_cache[url]) {
concept.repr = repr_cache[url];
concept.repr_means = repr_cache[url+'_means'];
updateCanvasesWithLastClicked();
return;
}
concept.repr = null;
concept.repr_means = null;
concept.repr_loading_started = Date.now();
// backup current model name and position, as they might change during the fetch
const current_model_name_backup = current_model.name;
const current_position_backup = current_position;
fetch(`representations/${current_model.short}/${concept.name}/repr-${current_position}.bin`)
fetch(url)
.then(response => response.arrayBuffer())
.then(buffer => {

Expand All @@ -205,6 +213,8 @@ <h1 style="text-align: center;">H-Space similarity explorer</h1>
}
}
concept.repr_means = means;
repr_cache[url] = repr;
repr_cache[url+'_means'] = means;
// update convases as the representations are available now
updateCanvasesWithLastClicked();
})
Expand Down

0 comments on commit cc3c883

Please sign in to comment.