Handling bloom prefix. (#1090)
# 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
702d269729
commit
85acb11ba0
|
@ -74,7 +74,7 @@ class BLOOMSharded(CausalLM):
|
||||||
torch.distributed.barrier(group=self.process_group)
|
torch.distributed.barrier(group=self.process_group)
|
||||||
filenames = weight_files(model_id, revision=revision, extension=".safetensors")
|
filenames = weight_files(model_id, revision=revision, extension=".safetensors")
|
||||||
weights = Weights(
|
weights = Weights(
|
||||||
filenames, device=device, dtype=dtype, process_group=self.process_group
|
filenames, device=device, dtype=dtype, process_group=self.process_group, prefix="transformer",
|
||||||
)
|
)
|
||||||
if config.quantize == "gptq":
|
if config.quantize == "gptq":
|
||||||
weights._set_gptq_params(model_id)
|
weights._set_gptq_params(model_id)
|
||||||
|
|
|
@ -16,6 +16,7 @@ class Weights:
|
||||||
dtype,
|
dtype,
|
||||||
process_group,
|
process_group,
|
||||||
aliases: Optional[Dict[str, List[str]]] = None,
|
aliases: Optional[Dict[str, List[str]]] = None,
|
||||||
|
prefix: Optional[str] = None
|
||||||
):
|
):
|
||||||
routing = {}
|
routing = {}
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
|
@ -33,6 +34,7 @@ class Weights:
|
||||||
self.device = device
|
self.device = device
|
||||||
self.dtype = dtype
|
self.dtype = dtype
|
||||||
self.process_group = process_group
|
self.process_group = process_group
|
||||||
|
self.prefix = prefix
|
||||||
self._handles = {}
|
self._handles = {}
|
||||||
|
|
||||||
def _get_handle(self, filename):
|
def _get_handle(self, filename):
|
||||||
|
@ -43,15 +45,22 @@ class Weights:
|
||||||
return self._handles[filename]
|
return self._handles[filename]
|
||||||
|
|
||||||
def get_filename(self, tensor_name: str) -> (str, str):
|
def get_filename(self, tensor_name: str) -> (str, str):
|
||||||
filename = self.routing.get(tensor_name, None)
|
|
||||||
if filename is None:
|
names = [tensor_name]
|
||||||
aliases = self.aliases.get(tensor_name, [])
|
if self.prefix is not None:
|
||||||
|
prefixed = f"{self.prefix}.{tensor_name}"
|
||||||
|
names.append(prefixed)
|
||||||
|
for name in names:
|
||||||
|
filename = self.routing.get(name, None)
|
||||||
|
if filename is not None:
|
||||||
|
return str(filename), name
|
||||||
|
|
||||||
|
aliases = self.aliases.get(name, [])
|
||||||
for alias in aliases:
|
for alias in aliases:
|
||||||
filename = self.routing.get(alias, None)
|
filename = self.routing.get(alias, None)
|
||||||
if filename is not None:
|
if filename is not None:
|
||||||
return str(filename), alias
|
return str(filename), alias
|
||||||
raise RuntimeError(f"weight {tensor_name} does not exist")
|
raise RuntimeError(f"weight {tensor_name} does not exist")
|
||||||
return str(filename), tensor_name
|
|
||||||
|
|
||||||
def _get_slice(self, tensor_name: str):
|
def _get_slice(self, tensor_name: str):
|
||||||
filename, tensor_name = self.get_filename(tensor_name)
|
filename, tensor_name = self.get_filename(tensor_name)
|
||||||
|
|
Loading…
Reference in New Issue