Fixing the download strategy for ibm-fms (#1917)
# What does this PR do? <!-- Congratulations! You've made it this far! You're not quite done yet though. Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution. Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change. Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost. --> <!-- Remove if not applicable --> Fixes # (issue) ## Before submitting - [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case). - [ ] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests), Pull Request section? - [ ] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link to it if that's the case. - [ ] Did you make sure to update the documentation with your changes? Here are the [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation). - [ ] Did you write any new necessary tests? ## Who can review? Anyone in the community is free to review the PR once the tests have passed. Feel free to tag members/contributors who may be interested in your PR. <!-- Your PR will be replied to more quickly if you can figure out the right person to tag with @ @OlivierDehaene OR @Narsil -->
This commit is contained in:
parent
5dad0c0b29
commit
f871f114ca
|
@ -154,31 +154,27 @@ def download_weights(
|
||||||
try:
|
try:
|
||||||
import json
|
import json
|
||||||
|
|
||||||
medusa_head = hf_hub_download(
|
config = hf_hub_download(
|
||||||
model_id, revision=revision, filename="medusa_lm_head.safetensors"
|
|
||||||
)
|
|
||||||
medusa_config = hf_hub_download(
|
|
||||||
model_id, revision=revision, filename="config.json"
|
model_id, revision=revision, filename="config.json"
|
||||||
)
|
)
|
||||||
with open(medusa_config, "r") as f:
|
with open(config, "r") as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
|
|
||||||
model_id = config["base_model_name_or_path"]
|
base_model_id = config.get("base_model_name_or_path", None)
|
||||||
revision = "main"
|
if base_model_id and base_model_id != model_id:
|
||||||
try:
|
try:
|
||||||
utils.weight_files(model_id, revision, extension)
|
logger.info(f"Downloading parent model {base_model_id}")
|
||||||
logger.info(
|
download_weights(
|
||||||
f"Files for parent {model_id} are already present on the host. "
|
model_id=base_model_id,
|
||||||
"Skipping download."
|
revision="main",
|
||||||
)
|
extension=extension,
|
||||||
return
|
auto_convert=auto_convert,
|
||||||
# Local files not found
|
logger_level=logger_level,
|
||||||
except (
|
json_output=json_output,
|
||||||
utils.LocalEntryNotFoundError,
|
trust_remote_code=trust_remote_code,
|
||||||
FileNotFoundError,
|
)
|
||||||
utils.EntryNotFoundError,
|
except Exception:
|
||||||
):
|
pass
|
||||||
pass
|
|
||||||
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -195,31 +191,6 @@ def download_weights(
|
||||||
if not extension == ".safetensors" or not auto_convert:
|
if not extension == ".safetensors" or not auto_convert:
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
elif (Path(model_id) / "medusa_lm_head.safetensors").exists():
|
|
||||||
# Try to load as a local Medusa model
|
|
||||||
try:
|
|
||||||
import json
|
|
||||||
|
|
||||||
medusa_head = Path(model_id) / "medusa_lm_head.safetensors"
|
|
||||||
medusa_config = Path(model_id) / "config.json"
|
|
||||||
with open(medusa_config, "r") as f:
|
|
||||||
config = json.load(f)
|
|
||||||
|
|
||||||
model_id = config["base_model_name_or_path"]
|
|
||||||
revision = "main"
|
|
||||||
try:
|
|
||||||
utils.weight_files(model_id, revision, extension)
|
|
||||||
logger.info(
|
|
||||||
f"Files for parent {model_id} are already present on the host. "
|
|
||||||
"Skipping download."
|
|
||||||
)
|
|
||||||
return
|
|
||||||
# Local files not found
|
|
||||||
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
|
||||||
pass
|
|
||||||
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
|
||||||
pass
|
|
||||||
|
|
||||||
elif (Path(model_id) / "adapter_config.json").exists():
|
elif (Path(model_id) / "adapter_config.json").exists():
|
||||||
# Try to load as a local PEFT model
|
# Try to load as a local PEFT model
|
||||||
try:
|
try:
|
||||||
|
@ -230,14 +201,43 @@ def download_weights(
|
||||||
return
|
return
|
||||||
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
||||||
pass
|
pass
|
||||||
|
elif (Path(model_id) / "config.json").exists():
|
||||||
|
# Try to load as a local Medusa model
|
||||||
|
try:
|
||||||
|
import json
|
||||||
|
|
||||||
|
config = Path(model_id) / "config.json"
|
||||||
|
with open(config, "r") as f:
|
||||||
|
config = json.load(f)
|
||||||
|
|
||||||
|
base_model_id = config.get("base_model_name_or_path", None)
|
||||||
|
if base_model_id:
|
||||||
|
try:
|
||||||
|
logger.info(f"Downloading parent model {base_model_id}")
|
||||||
|
download_weights(
|
||||||
|
model_id=base_model_id,
|
||||||
|
revision="main",
|
||||||
|
extension=extension,
|
||||||
|
auto_convert=auto_convert,
|
||||||
|
logger_level=logger_level,
|
||||||
|
json_output=json_output,
|
||||||
|
trust_remote_code=trust_remote_code,
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
||||||
|
pass
|
||||||
|
|
||||||
# Try to see if there are local pytorch weights
|
# Try to see if there are local pytorch weights
|
||||||
try:
|
try:
|
||||||
# Get weights for a local model, a hub cached model and inside the WEIGHTS_CACHE_OVERRIDE
|
# Get weights for a local model, a hub cached model and inside the WEIGHTS_CACHE_OVERRIDE
|
||||||
local_pt_files = utils.weight_files(model_id, revision, ".bin")
|
try:
|
||||||
|
local_pt_files = utils.weight_files(model_id, revision, ".bin")
|
||||||
|
except Exception:
|
||||||
|
local_pt_files = utils.weight_files(model_id, revision, ".pt")
|
||||||
|
|
||||||
# No local pytorch weights
|
# No local pytorch weights
|
||||||
except utils.LocalEntryNotFoundError:
|
except (utils.LocalEntryNotFoundError, utils.EntryNotFoundError):
|
||||||
if extension == ".safetensors":
|
if extension == ".safetensors":
|
||||||
logger.warning(
|
logger.warning(
|
||||||
f"No safetensors weights found for model {model_id} at revision {revision}. "
|
f"No safetensors weights found for model {model_id} at revision {revision}. "
|
||||||
|
|
|
@ -40,7 +40,6 @@ def _weight_hub_files_from_model_info(
|
||||||
and "arguments" not in s.rfilename
|
and "arguments" not in s.rfilename
|
||||||
and "args" not in s.rfilename
|
and "args" not in s.rfilename
|
||||||
and "training" not in s.rfilename
|
and "training" not in s.rfilename
|
||||||
and "medusa_lm_head" not in s.rfilename
|
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -57,7 +56,6 @@ def _weight_files_from_dir(d: Path, extension: str) -> List[str]:
|
||||||
and "args" not in f
|
and "args" not in f
|
||||||
and "adapter" not in f
|
and "adapter" not in f
|
||||||
and "training" not in f
|
and "training" not in f
|
||||||
and "medusa_lm_head" not in f
|
|
||||||
]
|
]
|
||||||
return filenames
|
return filenames
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue