Skip to content

Commit 35017ea

Browse files
gcf-owl-bot[bot]vchudnov-gparthea
authored
fix!: [google-ai-generativelanguage] make learning rate a one-of (googleapis#12462)
- [ ] Regenerate this pull request now. BEGIN_COMMIT_OVERRIDE fix!: make learning rate a one-of docs: A few small updates feat: Add `learning_rate_multiplier` to tuning `Hyperparameters` END_COMMIT_OVERRIDE PiperOrigin-RevId: 616144364 Source-Link: googleapis/googleapis@074ea98 Source-Link: https://github.com/googleapis/googleapis-gen/commit/299d3ea26a58923c0458c2afc5e8fe2d75a0ec77 Copy-Tag: eyJwIjoicGFja2FnZXMvZ29vZ2xlLWFpLWdlbmVyYXRpdmVsYW5ndWFnZS8uT3dsQm90LnlhbWwiLCJoIjoiMjk5ZDNlYTI2YTU4OTIzYzA0NThjMmFmYzVlOGZlMmQ3NWEwZWM3NyJ9 --------- Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com> Co-authored-by: Victor Chudnovsky <vchudnov@google.com> Co-authored-by: Anthonios Partheniou <partheniou@google.com>
1 parent 6f26fe8 commit 35017ea

12 files changed

Lines changed: 108 additions & 71 deletions

File tree

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/async_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,11 @@ async def sample_generate_answer():
487487
``SafetyCategory`` specified in the safety_settings. If
488488
there is no ``SafetySetting`` for a given
489489
``SafetyCategory`` provided in the list, the API will
490-
use the default safety setting for that category.
490+
use the default safety setting for that category. Harm
491+
categories HARM_CATEGORY_HATE_SPEECH,
492+
HARM_CATEGORY_SEXUALLY_EXPLICIT,
493+
HARM_CATEGORY_DANGEROUS_CONTENT,
494+
HARM_CATEGORY_HARASSMENT are supported.
491495
492496
This corresponds to the ``safety_settings`` field
493497
on the ``request`` instance; if ``request`` is provided, this

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -883,7 +883,11 @@ def sample_generate_answer():
883883
``SafetyCategory`` specified in the safety_settings. If
884884
there is no ``SafetySetting`` for a given
885885
``SafetyCategory`` provided in the list, the API will
886-
use the default safety setting for that category.
886+
use the default safety setting for that category. Harm
887+
categories HARM_CATEGORY_HATE_SPEECH,
888+
HARM_CATEGORY_SEXUALLY_EXPLICIT,
889+
HARM_CATEGORY_DANGEROUS_CONTENT,
890+
HARM_CATEGORY_HARASSMENT are supported.
887891
888892
This corresponds to the ``safety_settings`` field
889893
on the ``request`` instance; if ``request`` is provided, this

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/services/generative_service/transports/rest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,11 @@ def __call__(
798798
"uri": "/v1beta/{model=models/*}:generateContent",
799799
"body": "*",
800800
},
801+
{
802+
"method": "post",
803+
"uri": "/v1beta/{model=tunedModels/*}:generateContent",
804+
"body": "*",
805+
},
801806
]
802807
request, metadata = self._interceptor.pre_generate_content(
803808
request, metadata

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/types/generative_service.py

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,20 +181,19 @@ class GenerationConfig(proto.Message):
181181
Optional. The maximum number of tokens to include in a
182182
candidate.
183183
184-
If unset, this will default to output_token_limit specified
185-
in the ``Model`` specification.
184+
Note: The default value varies by model, see the
185+
``Model.output_token_limit`` attribute of the ``Model``
186+
returned from the ``getModel`` function.
186187
187188
This field is a member of `oneof`_ ``_max_output_tokens``.
188189
temperature (float):
189-
Optional. Controls the randomness of the output. Note: The
190-
default value varies by model, see the ``Model.temperature``
191-
attribute of the ``Model`` returned the ``getModel``
192-
function.
190+
Optional. Controls the randomness of the output.
193191
194-
Values can range from [0.0,1.0], inclusive. A value closer
195-
to 1.0 will produce responses that are more varied and
196-
creative, while a value closer to 0.0 will typically result
197-
in more straightforward responses from the model.
192+
Note: The default value varies by model, see the
193+
``Model.temperature`` attribute of the ``Model`` returned
194+
from the ``getModel`` function.
195+
196+
Values can range from [0.0, infinity).
198197
199198
This field is a member of `oneof`_ ``_temperature``.
200199
top_p (float):
@@ -210,7 +209,7 @@ class GenerationConfig(proto.Message):
210209
based on the cumulative probability.
211210
212211
Note: The default value varies by model, see the
213-
``Model.top_p`` attribute of the ``Model`` returned the
212+
``Model.top_p`` attribute of the ``Model`` returned from the
214213
``getModel`` function.
215214
216215
This field is a member of `oneof`_ ``_top_p``.
@@ -221,10 +220,10 @@ class GenerationConfig(proto.Message):
221220
The model uses combined Top-k and nucleus sampling.
222221
223222
Top-k sampling considers the set of ``top_k`` most probable
224-
tokens. Defaults to 40.
223+
tokens.
225224
226225
Note: The default value varies by model, see the
227-
``Model.top_k`` attribute of the ``Model`` returned the
226+
``Model.top_k`` attribute of the ``Model`` returned from the
228227
``getModel`` function.
229228
230229
This field is a member of `oneof`_ ``_top_k``.
@@ -655,7 +654,11 @@ class GenerateAnswerRequest(proto.Message):
655654
the default settings for each ``SafetyCategory`` specified
656655
in the safety_settings. If there is no ``SafetySetting`` for
657656
a given ``SafetyCategory`` provided in the list, the API
658-
will use the default safety setting for that category.
657+
will use the default safety setting for that category. Harm
658+
categories HARM_CATEGORY_HATE_SPEECH,
659+
HARM_CATEGORY_SEXUALLY_EXPLICIT,
660+
HARM_CATEGORY_DANGEROUS_CONTENT, HARM_CATEGORY_HARASSMENT
661+
are supported.
659662
temperature (float):
660663
Optional. Controls the randomness of the output.
661664

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/types/retriever.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class Document(proto.Message):
8888
Attributes:
8989
name (str):
9090
Immutable. Identifier. The ``Document`` resource name. The
91-
ID (name excluding the "corpora/*/documents/" prefix) can
91+
ID (name excluding the `corpora/*/documents/` prefix) can
9292
contain up to 40 characters that are lowercase alphanumeric
9393
or dashes (-). The ID cannot start or end with a dash. If
9494
the name is empty on create, a unique name will be derived
@@ -315,7 +315,7 @@ class Chunk(proto.Message):
315315
Attributes:
316316
name (str):
317317
Immutable. Identifier. The ``Chunk`` resource name. The ID
318-
(name excluding the "corpora/*/documents/*/chunks/" prefix)
318+
(name excluding the `corpora/*/documents/*/chunks/` prefix)
319319
can contain up to 40 characters that are lowercase
320320
alphanumeric or dashes (-). The ID cannot start or end with
321321
a dash. If the name is empty on create, a random

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/types/safety.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,12 @@ class HarmCategory(proto.Enum):
4444
Negative or harmful comments targeting
4545
identity and/or protected attribute.
4646
HARM_CATEGORY_TOXICITY (2):
47-
Content that is rude, disrepspectful, or
47+
Content that is rude, disrespectful, or
4848
profane.
4949
HARM_CATEGORY_VIOLENCE (3):
50-
Describes scenarios depictng violence against
51-
an individual or group, or general descriptions
52-
of gore.
50+
Describes scenarios depicting violence
51+
against an individual or group, or general
52+
descriptions of gore.
5353
HARM_CATEGORY_SEXUAL (4):
5454
Contains references to sexual acts or other
5555
lewd content.

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta/types/tuned_model.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,33 +268,57 @@ class TuningTask(proto.Message):
268268

269269

270270
class Hyperparameters(proto.Message):
271-
r"""Hyperparameters controlling the tuning process.
271+
r"""Hyperparameters controlling the tuning process. Read more at
272+
https://ai.google.dev/docs/model_tuning_guidance
273+
274+
This message has `oneof`_ fields (mutually exclusive fields).
275+
For each oneof, at most one member field can be set at the same time.
276+
Setting any member of the oneof automatically clears all other
277+
members.
272278
273279
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
274280
275281
Attributes:
282+
learning_rate (float):
283+
Optional. Immutable. The learning rate
284+
hyperparameter for tuning. If not set, a default
285+
of 0.001 or 0.0002 will be calculated based on
286+
the number of training examples.
287+
288+
This field is a member of `oneof`_ ``learning_rate_option``.
289+
learning_rate_multiplier (float):
290+
Optional. Immutable. The learning rate multiplier is used to
291+
calculate a final learning_rate based on the default
292+
(recommended) value. Actual learning rate :=
293+
learning_rate_multiplier \* default learning rate Default
294+
learning rate is dependent on base model and dataset size.
295+
If not set, a default of 1.0 will be used.
296+
297+
This field is a member of `oneof`_ ``learning_rate_option``.
276298
epoch_count (int):
277299
Immutable. The number of training epochs. An
278300
epoch is one pass through the training data. If
279-
not set, a default of 10 will be used.
301+
not set, a default of 5 will be used.
280302
281303
This field is a member of `oneof`_ ``_epoch_count``.
282304
batch_size (int):
283305
Immutable. The batch size hyperparameter for
284-
tuning. If not set, a default of 16 or 64 will
285-
be used based on the number of training
286-
examples.
306+
tuning. If not set, a default of 4 or 16 will be
307+
used based on the number of training examples.
287308
288309
This field is a member of `oneof`_ ``_batch_size``.
289-
learning_rate (float):
290-
Immutable. The learning rate hyperparameter
291-
for tuning. If not set, a default of 0.0002 or
292-
0.002 will be calculated based on the number of
293-
training examples.
294-
295-
This field is a member of `oneof`_ ``_learning_rate``.
296310
"""
297311

312+
learning_rate: float = proto.Field(
313+
proto.FLOAT,
314+
number=16,
315+
oneof="learning_rate_option",
316+
)
317+
learning_rate_multiplier: float = proto.Field(
318+
proto.FLOAT,
319+
number=17,
320+
oneof="learning_rate_option",
321+
)
298322
epoch_count: int = proto.Field(
299323
proto.INT32,
300324
number=14,
@@ -305,11 +329,6 @@ class Hyperparameters(proto.Message):
305329
number=15,
306330
optional=True,
307331
)
308-
learning_rate: float = proto.Field(
309-
proto.FLOAT,
310-
number=16,
311-
optional=True,
312-
)
313332

314333

315334
class Dataset(proto.Message):

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/async_client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,11 @@ async def sample_create_permission():
343343
role is a superset of the previous
344344
role's permitted operations:
345345
346-
- reader can use the resource (e.g.
346+
- reader can use the resource (e.g.
347347
tuned model) for inference
348-
- writer has reader's permissions and
348+
- writer has reader's permissions and
349349
additionally can edit and share
350-
- owner has writer's permissions and
350+
- owner has writer's permissions and
351351
additionally can delete
352352
353353
"""
@@ -473,11 +473,11 @@ async def sample_get_permission():
473473
role is a superset of the previous
474474
role's permitted operations:
475475
476-
- reader can use the resource (e.g.
476+
- reader can use the resource (e.g.
477477
tuned model) for inference
478-
- writer has reader's permissions and
478+
- writer has reader's permissions and
479479
additionally can edit and share
480-
- owner has writer's permissions and
480+
- owner has writer's permissions and
481481
additionally can delete
482482
483483
"""
@@ -729,11 +729,11 @@ async def sample_update_permission():
729729
role is a superset of the previous
730730
role's permitted operations:
731731
732-
- reader can use the resource (e.g.
732+
- reader can use the resource (e.g.
733733
tuned model) for inference
734-
- writer has reader's permissions and
734+
- writer has reader's permissions and
735735
additionally can edit and share
736-
- owner has writer's permissions and
736+
- owner has writer's permissions and
737737
additionally can delete
738738
739739
"""

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/client.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -764,11 +764,11 @@ def sample_create_permission():
764764
role is a superset of the previous
765765
role's permitted operations:
766766
767-
- reader can use the resource (e.g.
767+
- reader can use the resource (e.g.
768768
tuned model) for inference
769-
- writer has reader's permissions and
769+
- writer has reader's permissions and
770770
additionally can edit and share
771-
- owner has writer's permissions and
771+
- owner has writer's permissions and
772772
additionally can delete
773773
774774
"""
@@ -894,11 +894,11 @@ def sample_get_permission():
894894
role is a superset of the previous
895895
role's permitted operations:
896896
897-
- reader can use the resource (e.g.
897+
- reader can use the resource (e.g.
898898
tuned model) for inference
899-
- writer has reader's permissions and
899+
- writer has reader's permissions and
900900
additionally can edit and share
901-
- owner has writer's permissions and
901+
- owner has writer's permissions and
902902
additionally can delete
903903
904904
"""
@@ -1150,11 +1150,11 @@ def sample_update_permission():
11501150
role is a superset of the previous
11511151
role's permitted operations:
11521152
1153-
- reader can use the resource (e.g.
1153+
- reader can use the resource (e.g.
11541154
tuned model) for inference
1155-
- writer has reader's permissions and
1155+
- writer has reader's permissions and
11561156
additionally can edit and share
1157-
- owner has writer's permissions and
1157+
- owner has writer's permissions and
11581158
additionally can delete
11591159
11601160
"""

packages/google-ai-generativelanguage/google/ai/generativelanguage_v1beta3/services/permission_service/transports/rest.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ def __call__(
395395
role is a superset of the previous
396396
role's permitted operations:
397397
398-
- reader can use the resource (e.g.
398+
- reader can use the resource (e.g.
399399
tuned model) for inference
400-
- writer has reader's permissions and
400+
- writer has reader's permissions and
401401
additionally can edit and share
402-
- owner has writer's permissions and
402+
- owner has writer's permissions and
403403
additionally can delete
404404
405405
"""
@@ -588,11 +588,11 @@ def __call__(
588588
role is a superset of the previous
589589
role's permitted operations:
590590
591-
- reader can use the resource (e.g.
591+
- reader can use the resource (e.g.
592592
tuned model) for inference
593-
- writer has reader's permissions and
593+
- writer has reader's permissions and
594594
additionally can edit and share
595-
- owner has writer's permissions and
595+
- owner has writer's permissions and
596596
additionally can delete
597597
598598
"""
@@ -882,11 +882,11 @@ def __call__(
882882
role is a superset of the previous
883883
role's permitted operations:
884884
885-
- reader can use the resource (e.g.
885+
- reader can use the resource (e.g.
886886
tuned model) for inference
887-
- writer has reader's permissions and
887+
- writer has reader's permissions and
888888
additionally can edit and share
889-
- owner has writer's permissions and
889+
- owner has writer's permissions and
890890
additionally can delete
891891
892892
"""

0 commit comments

Comments
 (0)