-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat (examples): initial Stable Diffusion support (#715)
Signed-off-by: Alessandro Pappalardo <[email protected]>
- Loading branch information
Showing
16 changed files
with
439 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from brevitas.nn import QuantConv2d | ||
from brevitas.nn import QuantLinear | ||
|
||
|
||
class LoRACompatibleQuantConv2d(QuantConv2d): | ||
""" | ||
A QuantConv2d layer that can be used with as a replacement for LoRACompatibleConv. | ||
It doesn't actually support LoRA, it only matches the same forward pass. | ||
""" | ||
|
||
def forward(self, hidden_states, scale: float = 1.0): | ||
return super().forward(hidden_states) | ||
|
||
|
||
class LoRACompatibleQuantLinear(QuantLinear): | ||
""" | ||
A QuantLinear layer that can be used with as a replacement for LoRACompatibleLinear. | ||
It doesn't actually support LoRA, it only matches the same forward pass. | ||
""" | ||
|
||
def forward(self, hidden_states, scale: float = 1.0): | ||
return super().forward(hidden_states) |
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
Copyright (C) 2023, Advanced Micro Devices, Inc. All rights reserved. | ||
SPDX-License-Identifier: MIT | ||
""" | ||
|
||
import argparse | ||
import re | ||
|
||
|
||
class CustomValidator(object): | ||
|
||
def __init__(self, pattern): | ||
self._pattern = re.compile(pattern) | ||
|
||
def __call__(self, value): | ||
if not self._pattern.match(value): | ||
raise argparse.ArgumentTypeError( | ||
"Argument has to match '{}'".format(self._pattern.pattern)) | ||
return value | ||
|
||
|
||
quant_format_validator = CustomValidator(r"int|e[1-8]m[1-8]") | ||
|
||
|
||
def add_bool_arg(parser, name, default, help, str_true=False): | ||
dest = name.replace('-', '_') | ||
group = parser.add_mutually_exclusive_group(required=False) | ||
if str_true: | ||
group.add_argument('--' + name, dest=dest, type=str, help=help) | ||
else: | ||
group.add_argument('--' + name, dest=dest, action='store_true', help='Enable ' + help) | ||
group.add_argument('--no-' + name, dest=dest, action='store_false', help='Disable ' + help) | ||
parser.set_defaults(**{dest: default}) |
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
Empty file.
Oops, something went wrong.