Skip to content

Commit c7bd26d

Browse files
Add the workflow for co-working with the Gemini CLI. (#2453)
1 parent 780919d commit c7bd26d

File tree

1 file changed

+64
-2
lines changed

1 file changed

+64
-2
lines changed

CONTRIBUTING.md

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,16 +221,78 @@ If there's any error, the commit will not go through. Please fix the error (
221221
most of the times, the error is fixed automatically by the formatter/linter) and
222222
re-run the following:
223223

224-
```
224+
```shell
225225
git add .
226226
git commit -m "<message>" # This will not get logged as a duplicate commit.
227227
```
228228

229229
In case you want to run the above manually on all files, you can do the
230230
following:
231231

232-
```
232+
```shell
233233
pre-commit run --all-files
234234
```
235235

236236
KerasHub uses [Ruff](https://docs.astral.sh/ruff/) to format the code.
237+
238+
## Co-working with the Gemini CLI
239+
240+
Let's accelerate the development with Gemini CLI.
241+
242+
### Installation
243+
244+
Please refer to the Installation section at [https://github.com/google-gemini/gemini-cli](https://github.com/google-gemini/gemini-cli).
245+
246+
### Using the Gemini CLI
247+
248+
Start the CLI and analyze the project structure.
249+
250+
```shell
251+
gemini
252+
253+
# In the CLI.
254+
/init
255+
```
256+
257+
After running this, a `GEMINI.md` file will be generated in the project root. This file contains the project context that the Gemini CLI will use for subsequent tasks.
258+
259+
### Adding models
260+
261+
Taking `DINOV3` as a concrete example, you can instruct the CLI to help implement a new model by providing clear references and local context.
262+
263+
```shell
264+
# In the CLI.
265+
Add `DINOV3Backbone` at @keras_hub/src/models/dinov3. Refer to the implementation on HF here: https://github.com/huggingface/transformers/blob/main/src/transformers/models/dinov3_vit/modeling_dinov3_vit.py and consider the existing implementation of `dinov2` at @keras_hub/src/models/dinov2 for guidance.
266+
```
267+
268+
After the CLI generation, you should get some initial implementation for the model. Feel free to review and refine the code as needed.
269+
270+
Next, let's instruct the CLI to construct a numerical validation test to ensure the implementation is correct. Before running this step, make sure you have installed the `transformers` library and have access to the `facebook/dinov3-*` presets.
271+
272+
```shell
273+
# In the CLI.
274+
Create a numerical validation script `check_dinov3.py` for `DINOV3Backbone` at project root. Use the HF preset `facebook/dinov3-vits16-pretrain-lvd1689m` as a reference for the expected outputs. Remember to port the weights from HF to `DINOV3Backbone` within the script and refer to the existing implementation here: @keras_hub/src/utils/transformers/convert_dinov2.py
275+
```
276+
277+
Now, instruct the CLI to run the script and correct any errors. If you are working within Conda environments, be sure to also instruct the CLI to use the appropriate environment for execution.
278+
279+
```shell
280+
# In the CLI.
281+
Run @check_dinov3.py by `KERAS_BACKEND=jax conda run -n keras-hub-jax python check_dinov3.py`. Fix any errors encountered during execution.
282+
```
283+
284+
During this phase, human intervention is often necessary. You will need to carefully review the CLI's modifications and provide guidance or even handcraft some details that the tool failed to implement correctly.
285+
286+
Once you successfully complete the step above, you can now proceed to add the conversion script and unit tests for the `DINOV3Backbone`.
287+
288+
```shell
289+
# In the CLI.
290+
Create the conversion script `convert_dinov3.py` at @keras_hub/src/utils/transformers/convert_dinov3.py. Refer to the existing @keras_hub/src/utils/transformers/convert_dinov2.py at the same location for guidance.
291+
```
292+
293+
```shell
294+
# In the CLI.
295+
Create unit tests for `DINOV3Backbone` at @keras_hub/src/models/dinov3. Refer to the existing tests for `DINOV2Backbone` at @keras_hub/src/models/dinov2/dinov2_backbone_test.py for guidance.
296+
```
297+
298+
If you successfully run through all these steps, congratulations! You have now successfully added a new model to KerasHub through effective co-working with the Gemini CLI.

0 commit comments

Comments
 (0)