SciSharp / TensorFlow.NET

.NET Standard bindings for Google's TensorFlow for developing, training and deploying Machine Learning models in C# and F#.
https://scisharp.github.io/tensorflow-net-docs
Apache License 2.0
3.17k stars 506 forks source link

Breadth-first traversal of augmented graph view causes collection modification exception #1233

Open barfeous opened 4 months ago

barfeous commented 4 months ago

Description

Calling breadth_first_traversal on the AugmentedGraphView as done by the save method causes a "collection was modified; enumeration operation may not execute" exception because it's setting values on _children_cache[key].

Specifically:

` public class AugmentedGraphView: ObjectGraphView

//...

// around line 89 public override (IList, IDictionary<Trackable, IEnumerable>) breadth_first_traversal() {

// could we change this to // void get_merged_trackable(Trackable x)

    Trackable get_merged_trackable(Trackable x)
    {
        // TODO: complete it with new definitions `Asset` and `TrackableConstant`.
        return x;
    }
    var trackable_objects = base.breadth_first_traversal();

    foreach(var obj in _children_cache.Keys)
    {
        // skip the deletion of cache (maybe do it later).
        foreach(var pair in _children_cache[obj])
        {

// could we change this to // get_merged_trackable(pair.Value);

            _children_cache[obj][pair.Key] = get_merged_trackable(pair.Value);
        }
    }

    return base.breadth_first_traversal();
}`

Reproduction Steps

Call breadth_first_traversal on an AugmentedGraphView

Known Workarounds

None yet

Configuration and Other Information

This appears to be present in commit 197224f, and TF.NET 0.150.0.