Skip to content

Commit 26b4193

Browse files
gantezucchini-nlp
authored andcommitted
[CI] doc builder without custom image (huggingface#36862)
* no image * test * revert jax version updates * make fixup * update autodoc path for model_addition_debugger * shieldgemma2 * add missing pages to toctree
1 parent 1d93492 commit 26b4193

File tree

6 files changed

+29
-32
lines changed

6 files changed

+29
-32
lines changed

.github/workflows/build_pr_documentation.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,3 @@ jobs:
1515
pr_number: ${{ github.event.number }}
1616
package: transformers
1717
languages: ar de en es fr hi it ko pt tr zh ja te
18-
custom_container: huggingface/transformers-doc-builder

docs/source/en/_toctree.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,6 +985,8 @@
985985
title: Qwen2VL
986986
- local: model_doc/sam
987987
title: Segment Anything
988+
- local: model_doc/shieldgemma2
989+
title: ShieldGemma2
988990
- local: model_doc/siglip
989991
title: SigLIP
990992
- local: model_doc/siglip2
@@ -1044,6 +1046,8 @@
10441046
- sections:
10451047
- local: internal/modeling_utils
10461048
title: Custom Layers and Utilities
1049+
- local: internal/model_debugging_utils
1050+
title: Utilities for Model Debugging
10471051
- local: internal/pipelines_utils
10481052
title: Utilities for pipelines
10491053
- local: internal/tokenization_utils

docs/source/en/internal/model_debugging_utils.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Most of those are only useful if you are adding new models in the library.
2626

2727
### Model addition debugger - context manager for model adders
2828

29-
This context manager is a power user tool intended for model adders.
29+
This context manager is a power user tool intended for model adders.
3030
It tracks all forward calls within a model forward and logs a slice of each input and output on a nested Json.
3131
To note, this context manager enforces `torch.inference_mode()`.
3232

@@ -66,6 +66,6 @@ with model_addition_debugger_context(model, "optional_path_to_your_output_file.j
6666
```
6767

6868

69-
[[autodoc]] utils.model_addition_debugger
69+
[[autodoc]] model_addition_debugger
7070

71-
[[autodoc]] utils.model_addition_debugger_context
71+
[[autodoc]] model_addition_debugger_context

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@
121121
"importlib_metadata",
122122
"ipadic>=1.0.0,<2.0",
123123
"isort>=5.5.4",
124-
"jax>=0.4.27,<=0.4.38",
125-
"jaxlib>=0.4.27,<=0.4.38",
124+
"jax>=0.4.1,<=0.4.13",
125+
"jaxlib>=0.4.1,<=0.4.13",
126126
"jieba",
127127
"jinja2>=3.1.0",
128128
"kenlm",

src/transformers/dependency_versions_table.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
"importlib_metadata": "importlib_metadata",
2929
"ipadic": "ipadic>=1.0.0,<2.0",
3030
"isort": "isort>=5.5.4",
31-
"jax": "jax>=0.4.27,<=0.4.38",
32-
"jaxlib": "jaxlib>=0.4.27,<=0.4.38",
31+
"jax": "jax>=0.4.1,<=0.4.13",
32+
"jaxlib": "jaxlib>=0.4.1,<=0.4.13",
3333
"jieba": "jieba",
3434
"jinja2": "jinja2>=3.1.0",
3535
"kenlm": "kenlm",

src/transformers/models/shieldgemma2/modeling_shieldgemma2.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from ...utils import (
2626
add_start_docstrings_to_model_forward,
2727
logging,
28-
replace_return_docstrings,
2928
)
3029
from ...utils.deprecation import deprecate_kwarg
3130
from ..auto import AutoModelForImageTextToText
@@ -109,25 +108,6 @@
109108
Indices depicting the position of the input sequence tokens in the sequence. Contrarily to `position_ids`,
110109
this tensor is not affected by padding. It is used to update the cache in the correct position and to infer
111110
the complete sequence length.
112-
113-
Returns:
114-
A `ShieldGemma2ImageClassifierOutputWithNoAttention` instance continaing the logits and probabilities
115-
associated with the model predicting the `Yes` or `No` token as the response to that prompt, captured in the
116-
following properties.
117-
118-
* `logits` (`torch.Tensor` of shape `(batch_size, 2)`):
119-
The first position along dim=1 is the logits for the `Yes` token and the second position along dim=1 is
120-
the logits for the `No` token.
121-
* `probabilities` (`torch.Tensor` of shape `(batch_size, 2)`):
122-
The first position along dim=1 is the probability of predicting the `Yes` token and the second position
123-
along dim=1 is the probability of predicting the `No` token.
124-
125-
ShieldGemma prompts are constructed such that predicting the `Yes` token means the content *does violate* the
126-
policy as described. If you are only interested in the violative condition, use
127-
`violated = outputs.probabilities[:, 1]` to extract that slice from the output tensors.
128-
129-
When used with the `ShieldGemma2Processor`, the `batch_size` will be equal to `len(images) * len(policies)`,
130-
and the order within the batch will be img1_policy1, ... img1_policyN, ... imgM_policyN.
131111
"""
132112

133113

@@ -172,9 +152,6 @@ def tie_weights(self):
172152

173153
@deprecate_kwarg("num_logits_to_keep", version="4.50", new_name="logits_to_keep")
174154
@add_start_docstrings_to_model_forward(SHIELDGEMMA2_INPUTS_DOCSTRING)
175-
@replace_return_docstrings(
176-
output_type=ShieldGemma2ImageClassifierOutputWithNoAttention, config_class=_CONFIG_FOR_DOC
177-
)
178155
def forward(
179156
self,
180157
input_ids: torch.LongTensor = None,
@@ -193,9 +170,26 @@ def forward(
193170
logits_to_keep: Union[int, torch.Tensor] = 0,
194171
**lm_kwargs,
195172
) -> ShieldGemma2ImageClassifierOutputWithNoAttention:
196-
"""Predicts the binary probability that the image violates the speicfied policy.
173+
"""Predicts the binary probability that the image violates the specified policy.
197174
198175
Returns:
176+
A `ShieldGemma2ImageClassifierOutputWithNoAttention` instance containing the logits and probabilities
177+
associated with the model predicting the `Yes` or `No` token as the response to that prompt, captured in the
178+
following properties.
179+
180+
* `logits` (`torch.Tensor` of shape `(batch_size, 2)`):
181+
The first position along dim=1 is the logits for the `Yes` token and the second position along dim=1 is
182+
the logits for the `No` token.
183+
* `probabilities` (`torch.Tensor` of shape `(batch_size, 2)`):
184+
The first position along dim=1 is the probability of predicting the `Yes` token and the second position
185+
along dim=1 is the probability of predicting the `No` token.
186+
187+
ShieldGemma prompts are constructed such that predicting the `Yes` token means the content *does violate* the
188+
policy as described. If you are only interested in the violative condition, use
189+
`violated = outputs.probabilities[:, 1]` to extract that slice from the output tensors.
190+
191+
When used with the `ShieldGemma2Processor`, the `batch_size` will be equal to `len(images) * len(policies)`,
192+
and the order within the batch will be img1_policy1, ... img1_policyN, ... imgM_policyN.
199193
"""
200194
outputs = self.model(
201195
input_ids=input_ids,

0 commit comments

Comments
 (0)