-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap ForwardContext around full model forward (#789)
This PR adapts the ForwardContext to be applied to the full model (including head) forward pass. The original base model forward wrapper is now moved to `wrap_base` to make sure no second ForwardContext is created for a single forward pass. This enables passing custom args that are defined in the ForwardContext definition to the top-level model call, as discussed in #783, e.g.: ```python model = AutoModelForCausalLM.from_pretrained(model_name) adapters.init(model) tokenizer = AutoTokenizer.from_pretrained(model_name) inputs = tokenizer(["This is a test text"], return_tensors="pt") # Registers new forward args globally ForwardContext.context_args.add("task_ids") # New the new arg name can be used w/o modifying the model's forward method output = model(**inputs, task_ids=["id_0", "id_1"]) ``` In the example above, the forward context will automatically add the passed context args as attributes, ie. they can be accessed within the foward pass like this: ```python task_ids = ForwardContext.get_context().task_ids ```
- Loading branch information
Showing
27 changed files
with
132 additions
and
261 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.