FluidMLPRegressor crash on fit while running as kr

Hello all,

I found that FluidMLPRegressor will crash the server if I try to .fit while it is making a prediction via .kr. And when I say “while” I’m pretty sure that is very literal–as in, in the middle of making feedforward calculations. If I turn off the trig that is triggering the prediction calculations it is fine.

It’s really not a problem to ask the user to manage this stuff, which is what my code does now, but it did take a little thinking and poking today to try to figure out why my server was crashing… so maybe documenting it would be good. Example code below.

Thanks!

T

(
s.waitForBoot{
	Routine{
		var xcols = 100;
		var ycols = 3;
		var npoints = 500;
		var xdict = Dictionary.newFrom([
			"cols",xcols,
			"data",Dictionary.newFrom(Array.fill(npoints,{
				arg i;
				[i.asString,Array.fill(xcols,{rrand(0.0,1.0)})]
			}).flatten)
		]);
		var ydict = Dictionary.newFrom([
			"cols",ycols,
			"data",Dictionary.newFrom(Array.fill(npoints,{
				arg i;
				[i.asString,Array.fill(ycols,{rrand(0.0,1.0)})]
			}).flatten)
		]);

		~xds = FluidDataSet(s);
		~yds = FluidDataSet(s);

		s.sync;

		~xds.load(xdict);
		~yds.load(ydict);


		s.sync;
		~xds.print;
		~yds.print;

		~nn = FluidMLPRegressor(s,[50],FluidMLPRegressor.sigmoid,FluidMLPRegressor.identity);

		s.sync;

		~nn.fit(~xds,~yds,{
			arg loss;
			"loss: %".format(loss).postln;

			~synth = {
				arg trigRate = 1;
				var xsig = LFDNoise1.kr(1.dup(xcols)).range(0,1);
				var xbuf = LocalBuf(xcols);
				var ybuf = LocalBuf(ycols);
				var ysig;

				xsig.do({
					arg val, i;
					BufWr.kr(val,xbuf,i,1);
				});

				~nn.kr(Impulse.kr(trigRate),xbuf,ybuf);

				ysig = ycols.collect({
					arg i;
					BufRd.kr(1,ybuf,i,1,1);
				});

				ysig.poll;
			}.play;
		})
	}.play;
}
)

// this is very likely to be fine
~nn.fit(~xds,~yds);

// then do this
~synth.set(\trigRate,100);

// try this a few times and it will crash one of the times
~nn.fit(~xds,~yds);

Yes it is a known “feature” - it also happens in Max. What we thought should happen instead is that fit will block predict. More sensible I think :slight_smile:

1 Like