Git Product home page Git Product logo

fiddle's Introduction

Fiddle

Fiddle is a Python-first configuration library particularly well suited to ML applications. Fiddle enables deep configurability of parameters in a program, while allowing configuration to be expressed in readable and maintainable Python code.

Additional details can be found in the documentation.

Setup

Install Fiddle with pip:

pip install fiddle

Install Fiddle from source:

git clone https://github.com/google/fiddle
cd fiddle
python -m setup install

Import Fiddle:

import fiddle as fdl

fiddle's People

Contributors

agesmundo avatar ashishenoyp avatar chulayuth-a avatar dhgarrette avatar dhr avatar ebrevdo avatar edloper avatar jessefarebro avatar junwhanahn avatar laurentes avatar mungsoo avatar panzhufeng avatar ppwwyyxx avatar rickeylev avatar saeta avatar sun51 avatar tf-text-github-robot avatar yashk2810 avatar yilei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

fiddle's Issues

Parameter sharing for primitive types❓

The Fiddle tutorials describe how to use parameter sharing for any object, but what would be the right way to reuse the same value of the primitive type in multiple places (similar to ConfigDict.get_ref)?

The solution I've found so far relies on replacing the value of primitive type by an fdl.Config for a lambda, but I wonder if there is a better way?

!pip install fiddle-config

import fiddle as fdl
import dataclasses

@dataclasses.dataclass
class Obj:
  value: str

@dataclasses.dataclass
class BaseConfig:
  primitive: str 
  nested: Obj

def build_base():
  primitive = fdl.Config(lambda value: value, "NOT_SPECIFIED")
  obj = fdl.Config(Obj, value=primitive)
  return fdl.Config(BaseConfig, primitive=primitive, nested=obj)

c = build_base()
c.primitive.value = "NEW VALUE"
result = fdl.build(c)

print(result.nested.value)

(fiddle-config-0.1.0)

Incorrect signature parsing for subclass of Generic

from typing import Generic, TypeVar
T = TypeVar('T')

def print_sig(callable, *args, **kwargs):
    from fiddle._src import signatures
    kwargs = signatures.SignatureInfo.signature_binding(callable, *args, **kwargs)
    print(kwargs)

class A:
    def __init__(self, a, b=1):
        pass

class B(Generic[T]):
    def __init__(self, a, b=1):
        pass

print_sig(A, 3, 1)
print_sig(B, 3, 1)

Using github HEAD today, the above code prints:

{'a': 3, 'b': 1}
{'self': 3, 'a': 1}

Import error

I am trying to run this colab from the documentation but importing fails when running the first cell.

Collecting fiddle
  Downloading fiddle-0.2.2-py3-none-any.whl (233 kB)
     |████████████████████████████████| 233 kB 7.6 MB/s 
Requirement already satisfied: typing-extensions in /usr/local/lib/python3.7/dist-packages (from fiddle) (4.1.1)
Collecting libcst
  Downloading libcst-0.4.7-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.7 MB)
     |████████████████████████████████| 2.7 MB 54.7 MB/s 
Requirement already satisfied: pyyaml>=5.2 in /usr/local/lib/python3.7/dist-packages (from libcst->fiddle) (6.0)
Collecting typing-inspect>=0.4.0
  Downloading typing_inspect-0.8.0-py3-none-any.whl (8.7 kB)
Collecting mypy-extensions>=0.3.0
  Downloading mypy_extensions-0.4.3-py2.py3-none-any.whl (4.5 kB)
Installing collected packages: mypy-extensions, typing-inspect, libcst, fiddle
Successfully installed fiddle-0.2.2 libcst-0.4.7 mypy-extensions-0.4.3 typing-inspect-0.8.0
Traceback (most recent call last):

  File "/usr/local/lib/python3.7/dist-packages/IPython/core/interactiveshell.py", line 3326, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File ["<ipython-input-1-ba42286d1387>"](https://localhost:8080/#), line 3, in <module>
    import fiddle as fdl

  File "/usr/local/lib/python3.7/dist-packages/fiddle/__init__.py", line 18, in <module>
    from fiddle.building import build

  File "/usr/local/lib/python3.7/dist-packages/fiddle/building.py", line 22, in <module>
    from fiddle import config

  File "/usr/local/lib/python3.7/dist-packages/fiddle/config.py", line 86
    def __init__(self, fn_or_cls: Union['Buildable', TypeOrCallableProducingT], /,
                                                                                ^
SyntaxError: invalid syntax

Is there a way to dump a fiddle config as a nested dict?

Lets say I have a fiddle config that holds other fiddle configs (like in a typical modeling use case). I'm interested in dumping the outermost config to a dictionary such that the output holds the parameters and their arguments, as well as similar dictionaries for all of the nested configs (similar to pydantic v1's .dict()). Is this currently possible?

The use case is to improve logging, e.g. to Weights and Biases where I want to log every parameter as part of the config.

Thanks!

Comparison with other configuration frameworks

Hello,

I'd be interested to hear from fiddle's developers about the origins of fiddle.

  • What motivated the design of fiddle? Are there other specific frameworks or libraries from which fiddle draws inspiration?
  • Why were existing libraries/frameworks insufficient? Is fiddle solving a different problem, or is it an attempt to solve some of the same problems in a cleaner way?

Thanks.

Various issues blocking execution of `select_and_tag_apis.ipynb` notebook

I'm trying to run this notebook via Colab: https://colab.research.google.com/github/google/fiddle/blob/main/fiddle/examples/colabs/select_and_tag_apis.ipynb

Issue 1: missing module

Just running it directly, I run into the first issue: missing flax module. The error is on this line in code under the "Running example" section:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
[<ipython-input-2-c74d725d96dd>](https://localhost:8080/#) in <module>
      1 from typing import Any
      2 
----> 3 from flax import linen as nn
      4 from jax import numpy as jnp
      5 

ModuleNotFoundError: No module named 'flax'

---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Of course, we can include

!pip install flax

right above the first import line, so now our code will look as follows:

!pip install flax

from typing import Any

from flax import linen as nn
from jax import numpy as jnp

Issue 2: warning about JAX version

However, when we run this cell, first we get a warning after the installation of JAX:

WARNING: The following packages were previously imported in this runtime:
  [jax]
You must restart the runtime in order to use newly installed versions.

It would be nice to select the proper version(s) of Flax, JAX, etc. that are needed for this notebook.

Issue 3: error with selectors.select(...).replace(...)

Finally, the execution of the notebook fails with the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[<ipython-input-18-029051defc8e>](https://localhost:8080/#) in <module>
      5 
      6 
----> 7 graphviz.render(experiment_config())

[<ipython-input-18-029051defc8e>](https://localhost:8080/#) in experiment_config()
      1 def experiment_config() -> fdl.Config[Sequential]:
      2   cfg = base_config()
----> 3   selectors.select(cfg, tag=ActivationDType).replace(value=jnp.int32)
      4   return cfg
      5 

AttributeError: 'Selection' object has no attribute 'replace'

[Question] Push new release to PyPI

Hi folks! We are starting to use fiddle for configuration management but ran into an issue with building generic types. This is fixed in #522 but the release on PyPI is from August 2023. We built from source and things are working fine for now but could I request that a new, more recent release be created---it would simplify things a bit for us and I'm sure there are other new features/improvements that would be nice to pull in.

Keep Python3.8 Support

Python3.8 support was dropped in 6651b61. We would really want it back.

According to https://pypistats.org/packages/jax, Python3.8 has a very large user base among jax users:
2023-09-16_04-03

I use fiddle with PyTorch not jax, and 3.8 is still the most popular python version among its users:
2023-09-16_04-06

Although jax has dropped 3.8 support recently, the above pictures suggest that many of the ML community are using 3.8, therefore it's better if the ecosystem around it can support 3.8 for a little longer.

@vufg

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.