Last active
July 17, 2024 13:35
-
-
Save vjcitn/4bd8978e61779ecda7f74708708609c4 to your computer and use it in GitHub Desktop.
look at 'safetensors' component of bert (use after usebert.R succeeds)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# probe R user cache file system for bert resources | |
explore_bert = function() { | |
if (!requireNamespace("tibble")) stop("please install tibble to use this function") | |
res = dir(tools::R_user_dir("../huggingface/hub/models--google-bert--bert-base-uncased/snapshots/", "cache"), full=TRUE, recursive=TRUE) | |
if (length(res)<1) stop("not finding huggingface/hub or bert components in cache") | |
safetpath = grep("model.safetensors", res, value=TRUE) | |
st = try(reticulate::import("safetensors")) | |
if (inherits(st, "try-error")) stop("can't import safetensors with reticulate") | |
oo = st$safe_open(filename=safetpath, framework="pt") | |
kk = oo$keys() | |
allt = lapply(kk, function(x) oo$get_tensor(x)$shape$numel()) | |
tibble::as_tibble(data.frame(keys=kk, size=unlist(allt))) | |
} | |
print(explore_bert()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment