| 
 | 1 | +# Copyright 2025-present the HuggingFace Inc. team.  | 
 | 2 | + | 
 | 3 | +#  | 
 | 4 | +# Licensed under the Apache License, Version 2.0 (the "License");  | 
 | 5 | +# you may not use this file except in compliance with the License.  | 
 | 6 | +# You may obtain a copy of the License at  | 
 | 7 | +#  | 
 | 8 | +#     http://www.apache.org/licenses/LICENSE-2.0  | 
 | 9 | +#  | 
 | 10 | +# Unless required by applicable law or agreed to in writing, software  | 
 | 11 | +# distributed under the License is distributed on an "AS IS" BASIS,  | 
 | 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
 | 13 | +# See the License for the specific language governing permissions and  | 
 | 14 | +# limitations under the License.  | 
 | 15 | + | 
 | 16 | +from peft.import_utils import is_bnb_4bit_available, is_bnb_available  | 
 | 17 | +from peft.utils import register_peft_method  | 
 | 18 | + | 
 | 19 | +from .config import RandLoraConfig  | 
 | 20 | +from .layer import Linear, RandLoraLayer  | 
 | 21 | +from .model import RandLoraModel  | 
 | 22 | + | 
 | 23 | + | 
 | 24 | +__all__ = ["Linear", "RandLoraConfig", "RandLoraLayer", "RandLoraModel"]  | 
 | 25 | + | 
 | 26 | +register_peft_method(name="randlora", config_cls=RandLoraConfig, model_cls=RandLoraModel, prefix="randlora_")  | 
 | 27 | + | 
 | 28 | + | 
 | 29 | +def __getattr__(name):  | 
 | 30 | +    if (name == "Linear8bitLt") and is_bnb_available():  | 
 | 31 | +        from .bnb import Linear8bitLt  | 
 | 32 | + | 
 | 33 | +        return Linear8bitLt  | 
 | 34 | + | 
 | 35 | +    if (name == "Linear4bit") and is_bnb_4bit_available():  | 
 | 36 | +        from .bnb import Linear4bit  | 
 | 37 | + | 
 | 38 | +        return Linear4bit  | 
 | 39 | + | 
 | 40 | +    raise AttributeError(f"module {__name__} has no attribute {name}")  | 
0 commit comments