Update index.html
Browse files- index.html +20 -18
index.html
CHANGED
|
@@ -82,16 +82,16 @@
|
|
| 82 |
'Authorization': `Bearer ${hf_token}`
|
| 83 |
}
|
| 84 |
}
|
| 85 |
-
let
|
| 86 |
`https://huggingface.co/${hf_model}/raw/main/config.json`, auth
|
| 87 |
)
|
| 88 |
-
if (
|
| 89 |
throw new Error("Model is either private or gated, you must provide an access token")
|
| 90 |
}
|
| 91 |
-
if (
|
| 92 |
throw new Error("Model is either private or gated and provided access token does not have access to the repo")
|
| 93 |
}
|
| 94 |
-
let config = await
|
| 95 |
let model_size = 0
|
| 96 |
let dtype = parseInt(config["torch_dtype"].replaceAll(/\D/g, '')) / 8
|
| 97 |
try {
|
|
@@ -106,20 +106,22 @@
|
|
| 106 |
throw new Error("no size in pytorch metadata")
|
| 107 |
}
|
| 108 |
} catch {
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
|
|
|
|
|
|
| 123 |
}
|
| 124 |
}
|
| 125 |
config.parameters = model_size
|
|
|
|
| 82 |
'Authorization': `Bearer ${hf_token}`
|
| 83 |
}
|
| 84 |
}
|
| 85 |
+
let config_res = await fetch(
|
| 86 |
`https://huggingface.co/${hf_model}/raw/main/config.json`, auth
|
| 87 |
)
|
| 88 |
+
if (config_res.status === 401) {
|
| 89 |
throw new Error("Model is either private or gated, you must provide an access token")
|
| 90 |
}
|
| 91 |
+
if (config_res.status === 403) {
|
| 92 |
throw new Error("Model is either private or gated and provided access token does not have access to the repo")
|
| 93 |
}
|
| 94 |
+
let config = await config_res.json()
|
| 95 |
let model_size = 0
|
| 96 |
let dtype = parseInt(config["torch_dtype"].replaceAll(/\D/g, '')) / 8
|
| 97 |
try {
|
|
|
|
| 106 |
throw new Error("no size in pytorch metadata")
|
| 107 |
}
|
| 108 |
} catch {
|
| 109 |
+
try {
|
| 110 |
+
let model_page = await fetch(
|
| 111 |
+
`https://huggingface.co/${hf_model}`
|
| 112 |
+
).then(r => r.text())
|
| 113 |
+
let el = document.createElement( 'html' );
|
| 114 |
+
el.innerHTML = model_page
|
| 115 |
+
let params_el = el.querySelector('div[data-target="ModelSafetensorsParams"]')
|
| 116 |
+
if (params_el !== null) {
|
| 117 |
+
model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["safetensors"]["total"]
|
| 118 |
+
} else {
|
| 119 |
+
params_el = el.querySelector('div[data-target="ModelHeader"]')
|
| 120 |
+
model_size = JSON.parse(params_el.attributes.getNamedItem("data-props").value)["model"]["safetensors"]["total"]
|
| 121 |
+
}
|
| 122 |
+
} catch {
|
| 123 |
+
throw new Error("Couldn't determine model size from safetensor/pytorch index metadata nor from the model card. If the model is an unsharded pytorch model, it is not supported by this calculator.")
|
| 124 |
+
}
|
| 125 |
}
|
| 126 |
}
|
| 127 |
config.parameters = model_size
|