Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
37c205eb
Unverified
Commit
37c205eb
authored
Sep 20, 2023
by
Jinho Park
Committed by
GitHub
Sep 20, 2023
Browse files
Update bros checkpoint (#26277)
* fix bros integration test * update bros checkpoint
parent
86ffd5ff
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
25 deletions
+22
-25
src/transformers/models/bros/configuration_bros.py
src/transformers/models/bros/configuration_bros.py
+5
-5
src/transformers/models/bros/convert_bros_to_pytorch.py
src/transformers/models/bros/convert_bros_to_pytorch.py
+1
-1
src/transformers/models/bros/modeling_bros.py
src/transformers/models/bros/modeling_bros.py
+11
-11
tests/models/bros/test_modeling_bros.py
tests/models/bros/test_modeling_bros.py
+5
-8
No files found.
src/transformers/models/bros/configuration_bros.py
View file @
37c205eb
...
...
@@ -21,8 +21,8 @@ from ...utils import logging
logger
=
logging
.
get_logger
(
__name__
)
BROS_PRETRAINED_CONFIG_ARCHIVE_MAP
=
{
"
naver-clova-ocr
/bros-base-uncased"
:
"https://huggingface.co/
naver-clova-ocr
/bros-base-uncased/
resolve
/main/config.json"
,
"
naver-clova-ocr
/bros-large-uncased"
:
"https://huggingface.co/
naver-clova-ocr
/bros-large-uncased/
resolve
/main/config.json"
,
"
jinho8345
/bros-base-uncased"
:
"https://huggingface.co/
jinho8345
/bros-base-uncased/
blob
/main/config.json"
,
"
jinho8345
/bros-large-uncased"
:
"https://huggingface.co/
jinho8345
/bros-large-uncased/
blob
/main/config.json"
,
}
...
...
@@ -31,7 +31,7 @@ class BrosConfig(PretrainedConfig):
This is the configuration class to store the configuration of a [`BrosModel`] or a [`TFBrosModel`]. It is used to
instantiate a Bros model according to the specified arguments, defining the model architecture. Instantiating a
configuration with the defaults will yield a similar configuration to that of the Bros
[
naver-clova-ocr
/bros-base-uncased](https://huggingface.co/
naver-clova-ocr
/bros-base-uncased) architecture.
[
jinho8345
/bros-base-uncased](https://huggingface.co/
jinho8345
/bros-base-uncased) architecture.
Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model outputs. Read the
documentation from [`PretrainedConfig`] for more information.
...
...
@@ -81,10 +81,10 @@ class BrosConfig(PretrainedConfig):
```python
>>> from transformers import BrosConfig, BrosModel
>>> # Initializing a BROS
naver-clova-ocr
/bros-base-uncased style configuration
>>> # Initializing a BROS
jinho8345
/bros-base-uncased style configuration
>>> configuration = BrosConfig()
>>> # Initializing a model from the
naver-clova-ocr
/bros-base-uncased style configuration
>>> # Initializing a model from the
jinho8345
/bros-base-uncased style configuration
>>> model = BrosModel(configuration)
>>> # Accessing the model configuration
...
...
src/transformers/models/bros/convert_bros_to_pytorch.py
View file @
37c205eb
...
...
@@ -123,7 +123,7 @@ if __name__ == "__main__":
# Required parameters
parser
.
add_argument
(
"--model_name"
,
default
=
"
naver-clova-ocr
/bros-base-uncased"
,
default
=
"
jinho8345
/bros-base-uncased"
,
required
=
False
,
type
=
str
,
help
=
"Name of the original model you'd like to convert."
,
...
...
src/transformers/models/bros/modeling_bros.py
View file @
37c205eb
...
...
@@ -44,12 +44,12 @@ from .configuration_bros import BrosConfig
logger
=
logging
.
get_logger
(
__name__
)
_CHECKPOINT_FOR_DOC
=
"
naver-clova-ocr
/bros-base-uncased"
_CHECKPOINT_FOR_DOC
=
"
jinho8345
/bros-base-uncased"
_CONFIG_FOR_DOC
=
"BrosConfig"
BROS_PRETRAINED_MODEL_ARCHIVE_LIST
=
[
"
naver-clova-ocr
/bros-base-uncased"
,
"
naver-clova-ocr
/bros-large-uncased"
,
"
jinho8345
/bros-base-uncased"
,
"
jinho8345
/bros-large-uncased"
,
# See all Bros models at https://huggingface.co/models?filter=bros
]
...
...
@@ -846,9 +846,9 @@ class BrosModel(BrosPreTrainedModel):
>>> import torch
>>> from transformers import BrosProcessor, BrosModel
>>> processor = BrosProcessor.from_pretrained("
naver-clova-ocr
/bros-base-uncased")
>>> processor = BrosProcessor.from_pretrained("
jinho8345
/bros-base-uncased")
>>> model = BrosModel.from_pretrained("
naver-clova-ocr
/bros-base-uncased")
>>> model = BrosModel.from_pretrained("
jinho8345
/bros-base-uncased")
>>> encoding = processor("Hello, my dog is cute", add_special_tokens=False, return_tensors="pt")
>>> bbox = torch.tensor([[[0, 0, 1, 1]]]).repeat(1, encoding["input_ids"].shape[-1], 1)
...
...
@@ -1011,9 +1011,9 @@ class BrosForTokenClassification(BrosPreTrainedModel):
>>> import torch
>>> from transformers import BrosProcessor, BrosForTokenClassification
>>> processor = BrosProcessor.from_pretrained("
naver-clova-ocr
/bros-base-uncased")
>>> processor = BrosProcessor.from_pretrained("
jinho8345
/bros-base-uncased")
>>> model = BrosForTokenClassification.from_pretrained("
naver-clova-ocr
/bros-base-uncased")
>>> model = BrosForTokenClassification.from_pretrained("
jinho8345
/bros-base-uncased")
>>> encoding = processor("Hello, my dog is cute", add_special_tokens=False, return_tensors="pt")
>>> bbox = torch.tensor([[[0, 0, 1, 1]]]).repeat(1, encoding["input_ids"].shape[-1], 1)
...
...
@@ -1130,9 +1130,9 @@ class BrosSpadeEEForTokenClassification(BrosPreTrainedModel):
>>> import torch
>>> from transformers import BrosProcessor, BrosSpadeEEForTokenClassification
>>> processor = BrosProcessor.from_pretrained("
naver-clova-ocr
/bros-base-uncased")
>>> processor = BrosProcessor.from_pretrained("
jinho8345
/bros-base-uncased")
>>> model = BrosSpadeEEForTokenClassification.from_pretrained("
naver-clova-ocr
/bros-base-uncased")
>>> model = BrosSpadeEEForTokenClassification.from_pretrained("
jinho8345
/bros-base-uncased")
>>> encoding = processor("Hello, my dog is cute", add_special_tokens=False, return_tensors="pt")
>>> bbox = torch.tensor([[[0, 0, 1, 1]]]).repeat(1, encoding["input_ids"].shape[-1], 1)
...
...
@@ -1261,9 +1261,9 @@ class BrosSpadeELForTokenClassification(BrosPreTrainedModel):
>>> import torch
>>> from transformers import BrosProcessor, BrosSpadeELForTokenClassification
>>> processor = BrosProcessor.from_pretrained("
naver-clova-ocr
/bros-base-uncased")
>>> processor = BrosProcessor.from_pretrained("
jinho8345
/bros-base-uncased")
>>> model = BrosSpadeELForTokenClassification.from_pretrained("
naver-clova-ocr
/bros-base-uncased")
>>> model = BrosSpadeELForTokenClassification.from_pretrained("
jinho8345
/bros-base-uncased")
>>> encoding = processor("Hello, my dog is cute", add_special_tokens=False, return_tensors="pt")
>>> bbox = torch.tensor([[[0, 0, 1, 1]]]).repeat(1, encoding["input_ids"].shape[-1], 1)
...
...
tests/models/bros/test_modeling_bros.py
View file @
37c205eb
...
...
@@ -17,9 +17,8 @@
import
copy
import
unittest
from
transformers
import
BrosProcessor
from
transformers.testing_utils
import
require_torch
,
slow
,
torch_device
from
transformers.utils
import
cached_property
,
is_torch_available
,
is_vision_available
from
transformers.utils
import
is_torch_available
from
...test_configuration_common
import
ConfigTester
from
...test_modeling_common
import
ModelTesterMixin
,
ids_tensor
,
random_attention_mask
...
...
@@ -412,13 +411,10 @@ def prepare_bros_batch_inputs():
@
require_torch
class
BrosModelIntegrationTest
(
unittest
.
TestCase
):
@
cached_property
def
default_processor
(
self
):
return
BrosProcessor
.
from_pretrained
(
"naver-clova-ocr/bros-base-uncased"
)
if
is_vision_available
()
else
None
@
slow
def
test_inference_no_head
(
self
):
model
=
BrosModel
.
from_pretrained
(
"naver-clova-ocr/bros-base-uncased"
).
to
(
torch_device
)
model
=
BrosModel
.
from_pretrained
(
"jinho8345/bros-base-uncased"
).
to
(
torch_device
)
input_ids
,
bbox
,
attention_mask
=
prepare_bros_batch_inputs
()
with
torch
.
no_grad
():
...
...
@@ -434,7 +430,8 @@ class BrosModelIntegrationTest(unittest.TestCase):
self
.
assertEqual
(
outputs
.
last_hidden_state
.
shape
,
expected_shape
)
expected_slice
=
torch
.
tensor
(
[[
-
0.
4027
,
0.0756
,
-
0.
0647
],
[
-
0.0
1
92
,
-
0.
006
5
,
0.10
42
],
[
-
0.0
67
1
,
0.0
214
,
0.
0960
]]
[[
-
0.
3074
,
0.1363
,
0.
3143
],
[
0.092
5
,
-
0.
115
5
,
0.10
50
],
[
0.0
22
1
,
0.0
003
,
0.
1285
]]
).
to
(
torch_device
)
torch
.
set_printoptions
(
sci_mode
=
False
)
self
.
assertTrue
(
torch
.
allclose
(
outputs
.
last_hidden_state
[
0
,
:
3
,
:
3
],
expected_slice
,
atol
=
1e-4
))
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment