python / python/typeshed

Decoupling tensorflow from keras in stubs

オープン
#11,714 コメント 5 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stubs: improvement
主要言語
Python
スター
5.1k
フォーク
2.1k
平均マージ
1日 19時間
マージ済み PR(30日)
82

説明

Whilst working on https://github.com/python/typeshed/pull/11696, I was having issues referencing the source code. After reading the doc and a bit of investigation, I realized why:

The runtime of https://github.com/python/typeshed/tree/main/stubs/tensorflow/tensorflow/keras actually are just references to the keras source code at https://github.com/keras-team/keras/tree/master/keras (import keras), and is generated / injected in import tensorflow.keras by https://github.com/keras-team/keras/blob/6454a4888a494c20ab0ea1dc6912cbcc13c5f940/pip_build.py#L62

Even tensorflow's own doc links back to karas source code https://www.tensorflow.org/api_docs/python/tf/keras/callbacks/Callback

>>> from keras import callbacks
2024-04-03 23:28:35.387416: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
2024-04-03 23:28:36.959410: I tensorflow/core/util/port.cc:113] oneDNN custom operations are on. You may see slightly different numerical results due to floating-point round-off errors from different computation orders. To turn them off, set the environment variable `TF_ENABLE_ONEDNN_OPTS=0`.
>>> callbacks.__file__
'...\\typeshed\\.venv\\lib\\site-packages\\keras\\callbacks\\__init__.py'
>>> from tensorflow.keras import callbacks 
>>> callbacks.__file__
'...\\typeshed\\.venv\\lib\\site-packages\\keras\\callbacks\\__init__.py'

image

image

In other words, keras "pollutes" the tensorflow namespace! I don't know if the type stubs specifications allow two distributions to write to the same stub-only package, which would allow us to perfectly reflect what's truly happening. Second best thing would be to have stubs for keras and keep tensorflow.keras in the tensorflow stubs (since tensorflow is dependent on keras anyway)

CC @hoel-bagard & @hmc-cs-mdrissi

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

stubs/tensorflow/tensorflow/keras を Keras の pip_build.py およびリンクされたランタイムソースと併せて読み、tensorflow.keras がどのように注入されるかを理解します。サポートされる stub パッケージ構成についてメンテナーに確認します; 選択したレイアウトが namespace の曖昧さなしに keras と tensorflow.keras の両方を正確に表現できれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python, tensorflow
領域
devtools, machine-learning
issue の種類
リファクタリング
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。