Skip to content

Commit

Permalink
initial commit for PR
Browse files Browse the repository at this point in the history
Co-authored-by: Gabe Goodhart <gabe.l.hart@gmail.com>
  • Loading branch information
fabianlim and gabe-l-hart committed Nov 28, 2024
1 parent 5523e38 commit e299132
Show file tree
Hide file tree
Showing 15 changed files with 2,557 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/source/en/_toctree.yml
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,8 @@
sections:
- local: model_doc/albert
title: ALBERT
- local: model_doc/bamba
title: Bamba
- local: model_doc/bart
title: BART
- local: model_doc/barthez
Expand Down
1 change: 1 addition & 0 deletions docs/source/en/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Flax), PyTorch, and/or TensorFlow.
| [AltCLIP](model_doc/altclip) ||||
| [Audio Spectrogram Transformer](model_doc/audio-spectrogram-transformer) ||||
| [Autoformer](model_doc/autoformer) ||||
| [Bamba](model_doc/bamba) ||||
| [Bark](model_doc/bark) ||||
| [BART](model_doc/bart) ||||
| [BARThez](model_doc/barthez) ||||
Expand Down
66 changes: 66 additions & 0 deletions docs/source/en/model_doc/bamba.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!--Copyright 2024 The HuggingFace Team. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
specific language governing permissions and limitations under the License.
⚠️ Note that this file is in Markdown but contain specific syntax for our doc-builder (similar to MDX) that may not be
rendered properly in your Markdown viewer.
-->

# Bamba

## Overview

TODO

Tips:

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_path = "..."
tokenizer = AutoTokenizer.from_pretrained(model_path)

# drop device_map if running on CPU
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto")
model.eval()

# change input text as desired
prompt = "Write a code to find the maximum value in a list of numbers."

# tokenize the text
input_tokens = tokenizer(prompt, return_tensors="pt")
# generate output tokens
output = model.generate(**input_tokens, max_new_tokens=100)
# decode output tokens into text
output = tokenizer.batch_decode(output)
# loop over the batch to print, in this example the batch size is 1
for i in output:
print(i)
```

<!-- update this -->
This model was contributed by [...](https://huggingface.co/...).


## BambaConfig

[[autodoc]] BambaConfig

## BambaModel

[[autodoc]] BambaModel
- forward

## BambaForCausalLM

[[autodoc]] BambaForCausalLM
- forward
2 changes: 2 additions & 0 deletions docs/source/en/perf_infer_gpu_one.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ FlashAttention-2 is experimental and may change considerably in future versions.

FlashAttention-2 is currently supported for the following architectures:
* [Bark](https://huggingface.co/docs/transformers/model_doc/bark#transformers.BarkModel)
* [Bamba](https://huggingface.co/docs/transformers/model_doc/bart#transformers.BambaModel)
* [Bart](https://huggingface.co/docs/transformers/model_doc/bart#transformers.BartModel)
* [Chameleon](https://huggingface.co/docs/transformers/model_doc/chameleon#transformers.Chameleon)
* [CLIP](https://huggingface.co/docs/transformers/model_doc/clip#transformers.CLIPModel)
Expand Down Expand Up @@ -217,6 +218,7 @@ PyTorch's [`torch.nn.functional.scaled_dot_product_attention`](https://pytorch.o
For now, Transformers supports SDPA inference and training for the following architectures:
* [Albert](https://huggingface.co/docs/transformers/model_doc/albert#transformers.AlbertModel)
* [Audio Spectrogram Transformer](https://huggingface.co/docs/transformers/model_doc/audio-spectrogram-transformer#transformers.ASTModel)
* [Bamba](https://huggingface.co/docs/transformers/model_doc/bart#transformers.BambaModel)
* [Bart](https://huggingface.co/docs/transformers/model_doc/bart#transformers.BartModel)
* [Bert](https://huggingface.co/docs/transformers/model_doc/bert#transformers.BertModel)
* [BioGpt](https://huggingface.co/docs/transformers/model_doc/biogpt#transformers.BioGptModel)
Expand Down
14 changes: 14 additions & 0 deletions src/transformers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@
"AutoTokenizer",
],
"models.autoformer": ["AutoformerConfig"],
"models.bamba": ["BambaConfig"],
"models.bark": [
"BarkCoarseConfig",
"BarkConfig",
Expand Down Expand Up @@ -1503,6 +1504,13 @@
"AutoformerPreTrainedModel",
]
)
_import_structure["models.bamba"].extend(
[
"BambaForCausalLM",
"BambaModel",
"BambaPreTrainedModel",
]
)
_import_structure["models.bark"].extend(
[
"BarkCausalModel",
Expand Down Expand Up @@ -5043,6 +5051,7 @@
from .models.autoformer import (
AutoformerConfig,
)
from .models.bamba import BambaConfig
from .models.bark import (
BarkCoarseConfig,
BarkConfig,
Expand Down Expand Up @@ -6407,6 +6416,11 @@
AutoformerModel,
AutoformerPreTrainedModel,
)
from .models.bamba import (
BambaForCausalLM,
BambaModel,
BambaPreTrainedModel
)
from .models.bark import (
BarkCausalModel,
BarkCoarseModel,
Expand Down
1 change: 1 addition & 0 deletions src/transformers/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
audio_spectrogram_transformer,
auto,
autoformer,
bamba,
bark,
bart,
barthez,
Expand Down
2 changes: 2 additions & 0 deletions src/transformers/models/auto/configuration_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
("altclip", "AltCLIPConfig"),
("audio-spectrogram-transformer", "ASTConfig"),
("autoformer", "AutoformerConfig"),
("bamba", "BambaConfig"),
("bark", "BarkConfig"),
("bart", "BartConfig"),
("beit", "BeitConfig"),
Expand Down Expand Up @@ -328,6 +329,7 @@
("altclip", "AltCLIP"),
("audio-spectrogram-transformer", "Audio Spectrogram Transformer"),
("autoformer", "Autoformer"),
("bamba", "Bamba"),
("bark", "Bark"),
("bart", "BART"),
("barthez", "BARThez"),
Expand Down
2 changes: 2 additions & 0 deletions src/transformers/models/auto/modeling_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
("altclip", "AltCLIPModel"),
("audio-spectrogram-transformer", "ASTModel"),
("autoformer", "AutoformerModel"),
("bamba", "BambaModel"),
("bark", "BarkModel"),
("bart", "BartModel"),
("beit", "BeitModel"),
Expand Down Expand Up @@ -463,6 +464,7 @@
MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = OrderedDict(
[
# Model for Causal LM mapping
("bamba", "BambaForCausalLM"),
("bart", "BartForCausalLM"),
("bert", "BertLMHeadModel"),
("bert-generation", "BertGenerationDecoder"),
Expand Down
57 changes: 57 additions & 0 deletions src/transformers/models/bamba/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Copyright 2024 IBM and the HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from typing import TYPE_CHECKING

from ...utils import (
OptionalDependencyNotAvailable,
_LazyModule,
is_torch_available,
)


_import_structure = {
"configuration_bamba": ["BambaConfig"],
}

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
_import_structure["modeling_bamba"] = [
"BambaForCausalLM",
"BambaModel",
"BambaPreTrainedModel",
]

if TYPE_CHECKING:
from .configuration_bamba import BambaConfig

try:
if not is_torch_available():
raise OptionalDependencyNotAvailable()
except OptionalDependencyNotAvailable:
pass
else:
from .modeling_bamba import (
BambaForCausalLM,
BambaModel,
BambaPreTrainedModel,
)

else:
import sys

sys.modules[__name__] = _LazyModule(__name__, globals()["__file__"], _import_structure, module_spec=__spec__)
Loading

0 comments on commit e299132

Please sign in to comment.