Fix local load for Medusa (#1420)
# 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 --> Close #1418 Close #1415 ## 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
fbeb1c4475
commit
da27fbdfdb
|
@ -198,6 +198,35 @@ 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.pt").exists():
|
||||||
|
# Try to load as a local Medusa model
|
||||||
|
try:
|
||||||
|
import json
|
||||||
|
|
||||||
|
medusa_head = Path(model_id) / "medusa_lm_head.pt"
|
||||||
|
if auto_convert:
|
||||||
|
medusa_sf = Path(model_id) / "medusa_lm_head.safetensors"
|
||||||
|
if not medusa_sf.exists():
|
||||||
|
utils.convert_files([Path(medusa_head)], [medusa_sf], [])
|
||||||
|
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:
|
||||||
|
|
|
@ -71,15 +71,26 @@ class FlashLlama(FlashCausalLM):
|
||||||
from text_generation_server.utils.medusa import MedusaModel
|
from text_generation_server.utils.medusa import MedusaModel
|
||||||
from huggingface_hub import hf_hub_download
|
from huggingface_hub import hf_hub_download
|
||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
is_local_model = (Path(use_medusa).exists() and Path(use_medusa).is_dir()) or os.getenv(
|
||||||
|
"WEIGHTS_CACHE_OVERRIDE", None
|
||||||
|
) is not None
|
||||||
|
|
||||||
|
if not is_local_model:
|
||||||
medusa_config = hf_hub_download(
|
medusa_config = hf_hub_download(
|
||||||
use_medusa, revision=revision, filename="config.json"
|
use_medusa, revision=revision, filename="config.json"
|
||||||
)
|
)
|
||||||
with open(medusa_config, "r") as f:
|
|
||||||
config = json.load(f)
|
|
||||||
medusa_head = hf_hub_download(
|
medusa_head = hf_hub_download(
|
||||||
use_medusa, revision=revision, filename="medusa_lm_head.pt"
|
use_medusa, revision=revision, filename="medusa_lm_head.pt"
|
||||||
)
|
)
|
||||||
|
else:
|
||||||
|
medusa_config = str(Path(use_medusa) / "config.json")
|
||||||
|
medusa_head = str(Path(use_medusa) / "medusa_lm_head.pt")
|
||||||
|
|
||||||
|
with open(medusa_config, "r") as f:
|
||||||
|
config = json.load(f)
|
||||||
medusa_sf = medusa_head[: -len(".pt")] + ".safetensors"
|
medusa_sf = medusa_head[: -len(".pt")] + ".safetensors"
|
||||||
weights = Weights(
|
weights = Weights(
|
||||||
[medusa_sf], device, dtype, process_group=self.process_group
|
[medusa_sf], device, dtype, process_group=self.process_group
|
||||||
|
|
Loading…
Reference in New Issue