Giter VIP home page Giter VIP logo

ott's People

Contributors

adrhill avatar alantian avatar antoinebelloir avatar awehenkel avatar bamos avatar bosr avatar bunnech avatar daniel-packer avatar ersisimou avatar geoff-davis avatar giovp avatar gjhuizing avatar jtt94 avatar laetitiapapaxanthos avatar lucaeyring avatar marcocuturi avatar meyerscetbon avatar michalk8 avatar mucdk avatar olivierteboul avatar othmanesebbouh avatar pierreablin avatar sauravmaheshkar avatar theouscidda6 avatar zoepiran avatar

Forkers

gocato farbodch

ott's Issues

self.state_eta is not initialized when self.rescaling_a is None

Describe the bug

    # ott/src/ott/neural/flows/genot.py
    333 if self.checkpoint_manager is not None:
    334   states_to_save = {"state_velocity_field": self.state_velocity_field}
--> 335   if self.state_eta is not None:
    336     states_to_save["state_eta"] = self.state_eta
    337   if self.state_xi is not None:

AttributeError: 'GENOT' object has no attribute 'state_eta'

To Reproduce
I initialized genot as follows:

iterations=3

# ot_solver = sinkhorn.Sinkhorn()
ot_solver = gromov_wasserstein.GromovWasserstein(epsilon=1e-3)
time_sampler = sample_uniformly
optimizer = optax.adam(learning_rate=1e-4)
options = orbax.checkpoint.CheckpointManagerOptions(max_to_keep=2, create=True)
orbax_checkpointer = orbax.checkpoint.PyTreeCheckpointer()
checkpoint_manager = orbax.checkpoint.CheckpointManager(
    os.path.join("./ckpts_genots", "genot_test_saving.ckpt"),
    orbax_checkpointer,
    options
)

genot = GENOT(
    velocity_field = neural_vf,
    input_dim = source_dim,
    output_dim = target_dim,
    cond_dim = condition_dim,
    iterations = iterations,
    valid_freq = iterations-1,
    ot_solver = ot_solver,
    epsilon = None,
    cost_fn = Euclidean(),
    scale_cost = 1.0,
    optimizer = optimizer,
    flow = ConstantNoiseFlow(0.0),
    time_sampler = time_sampler,
    checkpoint_manager = checkpoint_manager,
    k_samples_per_x = 1,
    solver_latent_to_data = None,
    kwargs_solver_latent_to_data = {},
    fused_penalty = 0.,
    tau_a = 1., 
    tau_b = 1.,
    rescaling_a  = None,
    rescaling_b = None,
    unbalanced_kwargs = {},
    callback_fn = None,
    rng = None,
)
genot(dl, dl) # <-- error occurs here

Expected behavior
No error to be raised ;)

Additional context
I think the problem is that self.state_eta (which is inherited from the UnbalancednessMixin) is only initialized if rescaling_a is not None, see here: https://github.com/MUCDK/ott/blob/draft/neural_base_solver/src/ott/neural/models/base_solver.py#L339:L346
If rescaling_a is None, self.state_eta will not exist --> hence the error. The same might be true for self.opt_eta, self.opt_xi and self.state_xi - but I didn't properly check this.

I think this can be fixed by implementing the else case where the corresponding variables are set to None.

OTDataSet indexing error when number of source and target samples differ

Describe the bug
The OTDataSet seems to assume that we have equally many samples from source and target. If this is not the case, in particular if there are more source than target samples, this will lead to an error:

File "/p/project/dynadis/soeren.becker/repos/ott/src/ott/neural/flow_models/genot.py", line 400, in __call__
    for batch in tqdm(train_loader):
  File "/p/project/dynadis/soeren.becker/envs/env_genot_spim2/lib/python3.11/site-packages/tqdm/std.py", line 1181, in __iter__
    for obj in iterable:
  File "/p/project/dynadis/soeren.becker/envs/env_genot_spim2/lib/python3.11/site-packages/torch/utils/data/dataloader.py", line 631, in __next__
    data = self._next_data()
           ^^^^^^^^^^^^^^^^^
  File "/p/project/dynadis/soeren.becker/envs/env_genot_spim2/lib/python3.11/site-packages/torch/utils/data/dataloader.py", line 675, in _next_data
    data = self._dataset_fetcher.fetch(index)  # may raise StopIteration
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/p/project/dynadis/soeren.becker/envs/env_genot_spim2/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 51, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/p/project/dynadis/soeren.becker/envs/env_genot_spim2/lib/python3.11/site-packages/torch/utils/data/_utils/fetch.py", line 51, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
            ~~~~~~~~~~~~^^^^^
  File "/p/project/dynadis/soeren.becker/repos/ott/src/ott/neural/data/dataloaders.py", line 77, in __getitem__
    self.target_lin[idx] if self.target_lin is not None else [],
    ~~~~~~~~~~~~~~~^^^^^
IndexError: index 20615 is out of bounds for axis 0 with size 16361

To Reproduce
Initialize dataloader with fewer target samples than source samples and train genot with it.

Expected behavior
No indexing error.

Additional context
The error arises as you set the len of the dataset only based on the number of source samples:
https://github.com/MUCDK/ott/blob/draft/neural_base_solver/src/ott/neural/data/dataloaders.py#L88:L90

Aside from this: Using a single index for both source and target as here https://github.com/MUCDK/ott/blob/draft/neural_base_solver/src/ott/neural/data/dataloaders.py#L70:L86
means that you always load "pairs", i.e., index-corresponding source and target samples will be part of every minibatch. Source and target samples in the minibatch are hence not fully i.i.d., I think.

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.