Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize setTimeout #6694

Merged
merged 8 commits into from
Sep 27, 2022
Merged

Customize setTimeout #6694

merged 8 commits into from
Sep 27, 2022

Conversation

gyagp
Copy link

@gyagp gyagp commented Jul 29, 2022

If the setTimeout nesting level is greater than 5 and timeout is less
than 4ms, timeout will be clamped to 4ms, which hurts the perf. A custom
setTimeout is provided to mitigate the perf impact.

BUG: #6687

To see the logs from the Cloud Build CI, please join either our discussion or announcement mailing list.


This change is Reviewable

@gyagp
Copy link
Author

gyagp commented Jul 29, 2022

This PR is still WIP. @qjia7 @xhcao PTAL to see if you have any high-level comments. Do you have a good idea to write some test cases for this?

@qjia7
Copy link
Contributor

qjia7 commented Aug 1, 2022

This PR is still WIP. @qjia7 @xhcao PTAL to see if you have any high-level comments. Do you have a good idea to write some test cases for this?

The implementation looks good for me. How about enabling setTimeoutWPM behind a flag for a while? For the test case, maybe add a new file util_base_test.js. Test that repeat call setTimeoutWPM 20(or a larger number) times. And expect the avg time of the last 15 is less than 4 ms or less?

@xhcao
Copy link
Contributor

xhcao commented Aug 1, 2022

The function could be called by tf.profile, if you want to write unit cases. You could also view the total of tfjs-models' demos, the time could be reduced.

@gyagp
Copy link
Author

gyagp commented Aug 3, 2022

With above changes, I get below from unit test:
LOG: 'averageTime of setTimeoutWPM is 0.06666664282480876 ms'
LOG: 'averageTime of setTimeout is 4 ms'

Copy link
Collaborator

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 approvals obtained (waiting on @gyagp, @lina128, @Linchenn, @mattsoulanille, @qjia7, and @xhcao)


tfjs-core/src/util_base.ts line 765 at r1 (raw file):

  // If the setTimeout nesting level is greater than 5 and timeout is less than
  // 4ms, timeout will be clamped to 4ms, which hurts the perf. Interleaving
  // window.postMessage and setTimeout will trick the browser and avoid the

when the postMessage call will reset the timeout counting?


tfjs-core/src/util_base.ts line 770 at r1 (raw file):

    fns.push(fn);
    setTimeout(() => {
      window.postMessage({name: messageName, index: fns.length - 1}, '*');

I am curious why you use the index of the functions, instead of simply popping from the function array?


tfjs-core/src/util_base.ts line 780 at r1 (raw file):

      fn();
      handledMessageCount++;
      // console.log(`handledMessageCount=${handledMessageCount},

remove the comments?

Copy link
Collaborator

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 approvals obtained (waiting on @gyagp, @lina128, @Linchenn, @mattsoulanille, @qjia7, and @xhcao)


tfjs-core/src/util_base.ts line 758 at r1 (raw file):

}

if (!('setTimeoutWPM' in window)) {

is this only targeting browser? might be better to register this on the browser platform file.

Comment on lines 780 to 781
// console.log(`handledMessageCount=${handledMessageCount},
// fns.length=${fns.length}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// console.log(`handledMessageCount=${handledMessageCount},
// fns.length=${fns.length}`);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

};

window.addEventListener('message', handleMessage, true);
(window as any).setTimeoutWPM = setTimeoutWPM;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may be better to store this in _tfGlobals (instead of window), which you can get by calling getGlobalNamespace() from global_util.ts.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, since this relies on window, _tfGlobals may be the wrong place for it. Maybe we should add an optional setTimeoutWPM function to platform.ts and add the function itself to platform_browser.ts (like Ping suggested in his review).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to platform_browser.ts

Comment on lines 670 to 672
// If we set a larger number here, an error will be reported as "'expect'
// was used when there was no current spec, this could be because an
// asynchronous test timed out".
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because Jasmine does not know you're still testing setTimeout, so the expect called in the callback is actually called during another test (or after all tests are complete, which causes the error you're seeing). Marking the test as async or using a done callback should fix this. Docs

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I used done callback to solve this.

Comment on lines 691 to 692
// We don't have expect here as in some browsers, like Chrome Canary,
// nesting level threshold is set to 100 instead of 5.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the fix for totalCount above, you might be able to increase the count above 100 and add an expect. Otherwise, it may be best to remove this test or mark it with xit, since it doesn't appear to be testing anything (unless you're testing that no errors are thrown. If so, you should call expect().nothing()).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Increased to 100

const totalCount = 8;
const skipCount = 5;

it('setTimeout', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this test async or add a done callback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}
});

it('setTimeoutWPM', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make this test async or add a done callback.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

// was used when there was no current spec, this could be because an
// asynchronous test timed out".
const totalCount = 8;
const skipCount = 5;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Document what this does and why it exists.

Suggested change
const skipCount = 5;
// Skip the first few samples because the browser does not throttle them.
const skipCount = 5;

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments added

}
};

window.addEventListener('message', handleMessage, true);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be better to add this event listener when the user first calls setTimeoutWPM. That way, we don't pollute the event listener list if setTimeoutWPM is never used.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to first call to setTimeoutCustom.

Copy link
Collaborator

@Linchenn Linchenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with Ping. If this targets to browser, we probably have to move it to browser platform.

LGTM! Thank you Yang so much for investigating and fulfilling it!

Reviewable status: 0 of 1 approvals obtained (waiting on @gyagp, @lina128, @qjia7, and @xhcao)

@@ -303,7 +303,7 @@ export function rightPad(a: string, size: number): string {

export function repeatedTry(
checkFn: () => boolean, delayFn = (counter: number) => 0,
maxCounter?: number): Promise<void> {
maxCounter?: number, scheduleFn?: Function): Promise<void> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

environment.ts imports util_base, so we couldn't import environment in util_base, which will result in circular import. Thus I introduce scheduleFn here. If we need a custom scheduling function other than setTimeout, we can pass the function in. In our case, it's setTimeoutCustom() from WebGL side. In this way, repeatedTry() keeps to be platform independent.

@@ -82,3 +82,6 @@ ENV.registerFlag('ENGINE_COMPILE_ONLY', () => false);

/** Whether to enable canvas2d willReadFrequently for GPU backends */
ENV.registerFlag('CANVAS2D_WILL_READ_FREQUENTLY_FOR_GPU', () => false);

/** Whether to use setTimeoutCustom */
ENV.registerFlag('USE_SETTIMEOUTCUSTOM', () => false);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed to this name as even if we set it, we can't guarantee postMessage version setTimeout is called, as window might be not available in browser.

@@ -46,4 +46,6 @@ export interface Platform {
encode(text: string, encoding: string): Uint8Array;
/** Decode the provided bytes into a string using the provided encoding. */
decode(bytes: Uint8Array, encoding: string): string;

setTimeoutCustom?(functionRef: Function, delay: number): void;
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the parameter names to be aligned with setTimeout definition in browser (https://developer.mozilla.org/en-US/docs/Web/API/setTimeout).

Copy link
Author

@gyagp gyagp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 approvals obtained (waiting on @lina128, @mattsoulanille, @pyu10055, @qjia7, and @xhcao)


tfjs-core/src/util_base.ts line 758 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

is this only targeting browser? might be better to register this on the browser platform file.

moved to platform_browser


tfjs-core/src/util_base.ts line 765 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

when the postMessage call will reset the timeout counting?

The trick here is if we interleave the setTimeout and window.postMessage, it will break the nesting rule of setTimeout (calling setTimeout inside callback).


tfjs-core/src/util_base.ts line 770 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

I am curious why you use the index of the functions, instead of simply popping from the function array?

We may call setTimeout with different delays, which means the sequence of call may not be the sequence of callbacks. For example, setTimeout(cb0, 2); setTimeout(cb1, 1); cb1 should be called first, then cb0.


tfjs-core/src/util_base.ts line 780 at r1 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

remove the comments?

done

@gyagp
Copy link
Author

gyagp commented Aug 5, 2022

Thank you all for the comments! I think I have addressed all of them. Could you please take another look?
I also tested bodypix-MobileNetV1-image-0.25 and got below data (best time, average time):
[setTimeout]
16.5, 22.5
15.3, 20.7
15.8, 21.4
17.6, 23.2
17.4, 22.5

[setTimeoutCustom]
13.1, 16.0
13.2, 18.3
13.6, 15.8
12.7, 17.0
11.7, 15.2

The data shows we can get 2-4ms back.

It seems the bots are still not satisfied, but I couldn't figure out the reason after checking the detailed log. Could you please point me to the reason? Thanks!

Copy link
Collaborator

@Linchenn Linchenn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Yang! LGTM.

Reviewable status: 0 of 1 approvals obtained (waiting on @lina128, @mattsoulanille, @pyu10055, @qjia7, and @xhcao)

let count = 0;
let startTime = performance.now();
let totalTime = 0;
if (env().platformName === 'browser') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this check for the browser platform happen before this spec?

if (env().platformName === 'browser') {
  it('setTimeout', (done) => {
    ...
  });
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, if all the tests in this describe block need to run in the browser, you can replace it with

describeWithFlags('setTimeout', BROWSER_ENVS, () => {
  ...
});

Then, you won't have to check the platform on each test.

describeWithFlags
BROWSER_ENVS

@@ -303,7 +303,7 @@ export function rightPad(a: string, size: number): string {

export function repeatedTry(
checkFn: () => boolean, delayFn = (counter: number) => 0,
maxCounter?: number): Promise<void> {
maxCounter?: number, scheduleFn?: Function): Promise<void> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use setTimeout as the default value (see next comment for why).

Suggested change
maxCounter?: number, scheduleFn?: Function): Promise<void> {
maxCounter?: number, scheduleFn = setTimeout): Promise<void> {

The types here might not be correctly inferred, so you might have to manually specify

scheduleFn: (callback: () => void, time: number) => void

or something similar.

Comment on lines 324 to 328
if (typeof scheduleFn === 'undefined') {
setTimeout(tryFn, nextBackoff);
} else {
scheduleFn(tryFn, nextBackoff);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the default value of scheduleFunction to setTimeout to avoid this if statement.

Suggested change
if (typeof scheduleFn === 'undefined') {
setTimeout(tryFn, nextBackoff);
} else {
scheduleFn(tryFn, nextBackoff);
}
scheduleFn(tryFn, nextBackoff);

Yang Gu added 4 commits August 6, 2022 09:16
If the setTimeout nesting level is greater than 5 and timeout is less
than 4ms, timeout will be clamped to 4ms, which hurts the perf. A custom
setTimeout is provided to mitigate the perf impact.
Copy link
Author

@gyagp gyagp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 1 approvals obtained (waiting on @gyagp, @lina128, @mattsoulanille, @pyu10055, @qjia7, and @xhcao)


tfjs-core/src/util_base.ts line 328 at r4 (raw file):

Previously, mattsoulanille (Matthew Soulanille) wrote…

Set the default value of scheduleFunction to setTimeout to avoid this if statement.

      scheduleFn(tryFn, nextBackoff);

This looks more clean. done!


tfjs-core/src/platforms/platform_browser_test.ts line 102 at r4 (raw file):

Previously, mattsoulanille (Matthew Soulanille) wrote…

Actually, if all the tests in this describe block need to run in the browser, you can replace it with

describeWithFlags('setTimeout', BROWSER_ENVS, () => {
  ...
});

Then, you won't have to check the platform on each test.

describeWithFlags
BROWSER_ENVS

BROWSER_ENVS is much better. Thanks for the suggestion!

@@ -321,7 +323,7 @@ export function repeatedTry(
reject();
return;
}
setTimeout(tryFn, nextBackoff);
scheduleFn(tryFn, nextBackoff);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How do you think to always call setTimeoutCustom(tryFn, nextBackoff) here? And move setTimeoutCustom(tryFn, nextBackoff) to a common place since your current implementation setTimeoutCustom is already a common way and not only for webgl backend? In this case, you don't need to change gpgpu_context.ts?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should replace setTimeout with a custom one only in browser and window is ready. So platform browser may be a good place to host it.
util_base should not be dependent on any env, but setTimeoutCustom relies on env (for both platform check and flag check). So I'm afraid even with your suggestion, we still need to pass setTimeoutCustom as a parameter (Actually I introduced scheduleFn to avoid the dependency with env).

@gyagp
Copy link
Author

gyagp commented Aug 8, 2022

@pyu10055 Can you review again the latest changes? Thanks!

Copy link
Collaborator

@lina128 lina128 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you Yang! LGTM

@vladmandic
Copy link
Contributor

vladmandic commented Aug 9, 2022

I love this improvement as it results in quite significant performance improvements

but at the moment it causes conflict with @tensorflow/tfjs-backend-wasm as soon as that module is loaded
regardless if its used or not (IMO its due to bad behavior by EMScripten, but its a conflict non-the-less),

see #6687 (comment) for details

@gyagp
Copy link
Author

gyagp commented Aug 9, 2022

Thanks @vladmandic , I will investigate this.

Copy link
Collaborator

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @gyagp looks good to me, just couple minor comments.

Reviewable status: :shipit: complete! 3 of 1 approvals obtained (waiting on @gyagp, @mattsoulanille, @pyu10055, @qjia7, and @xhcao)


tfjs-core/src/platforms/platform.ts line 50 at r3 (raw file):

Previously, gyagp (Yang Gu) wrote…

I changed the parameter names to be aligned with setTimeout definition in browser (https://developer.mozilla.org/en-US/docs/Web/API/setTimeout).

To align with setTimeout, should it return the id for allowing clearTimeout API?


tfjs-core/src/platforms/platform_browser_test.ts line 112 at r5 (raw file):

      if (count === totalCount) {
        const averageTime = totalTime / (totalCount - skipCount);
        console.log(`averageTime of setTimeout is ${averageTime} ms`);

remove the console log


tfjs-core/src/platforms/platform_browser_test.ts line 140 at r5 (raw file):

      if (count === totalCount) {
        const averageTime = totalTime / (totalCount - skipCount);
        console.log(`averageTime of setTimeoutCustom is ${averageTime} ms`);

remove the console log


tfjs-core/src/platforms/platform_browser_test.ts line 141 at r5 (raw file):

        const averageTime = totalTime / (totalCount - skipCount);
        console.log(`averageTime of setTimeoutCustom is ${averageTime} ms`);
        if (window) {

since you are specifying browser_env, there is no need to test window variable, and the false branch should not be triggered

Copy link
Author

@gyagp gyagp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 3 of 1 approvals obtained (waiting on @gyagp, @mattsoulanille, @pyu10055, @qjia7, and @xhcao)


tfjs-core/src/platforms/platform.ts line 50 at r3 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

To align with setTimeout, should it return the id for allowing clearTimeout API?

I don't want to introduce the complexity to implement clearTimeoutCustom. Without it, it's useless to return id, so I intentionally set it as void.


tfjs-core/src/platforms/platform_browser_test.ts line 112 at r5 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

remove the console log

This is in the test and I intentionally added this to understand the setTimeout delay on various configurations, like node, safari, etc. The results may change as time goes by. For example, Chrome is increasing the throttle nesting level from 5 to 100, which may cause failure of this test in future. With this info, it should be easier to understand the reason.


tfjs-core/src/platforms/platform_browser_test.ts line 140 at r5 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

remove the console log

same as above


tfjs-core/src/platforms/platform_browser_test.ts line 141 at r5 (raw file):

Previously, pyu10055 (Ping Yu) wrote…

since you are specifying browser_env, there is no need to test window variable, and the false branch should not be triggered

I was thinking about running this in a worker. It should be unnecessary. Will remove in a follow-up PR.

@gyagp gyagp requested a review from pyu10055 August 11, 2022 10:38
Copy link
Collaborator

@pyu10055 pyu10055 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 3 of 6 files at r2, 2 of 4 files at r3, 1 of 2 files at r5, 1 of 1 files at r6, all commit messages.
Reviewable status: :shipit: complete! 3 of 1 approvals obtained (waiting on @gyagp, @mattsoulanille, @pyu10055, @qjia7, and @xhcao)


tfjs-core/src/platforms/platform_browser_test.ts line 141 at r5 (raw file):

Previously, gyagp (Yang Gu) wrote…

I was thinking about running this in a worker. It should be unnecessary. Will remove in a follow-up PR.

we run worker tests separately, and those tests are typically a separate file.

@gyagp
Copy link
Author

gyagp commented Sep 27, 2022

@pyu10055 @mattsoulanille, given related Emscripten issues were fixed (Thanks @vladmandic !) and @mattsoulanille upgraded Emscripten to include the fixes, can we merge this change now?

@mattsoulanille mattsoulanille merged commit ba66eb0 into tensorflow:master Sep 27, 2022
@gyagp gyagp deleted the settimeout branch September 28, 2022 01:20
dydavidkim added a commit to CodeSmithDSMLProjects/tfjs that referenced this pull request Sep 28, 2022
* Customize setTimeout (tensorflow#6694)

If the setTimeout nesting level is greater than 5 and timeout is less
than 4ms, timeout will be clamped to 4ms, which hurts the perf. A custom
setTimeout is provided to mitigate the perf impact.

BUG: tensorflow#6687
Co-authored-by: Na Li <[email protected]>

* Upgrade windows BrowserStack chrome to 104 (tensorflow#6866)

* webgpu: Disable importExternalTexture (tensorflow#6868)

WebGPU Working Group recently found some problem with
importExtenalTexture in spec, so we have to disable it temporarily.

Co-authored-by: Yang Gu <[email protected]>
Co-authored-by: Na Li <[email protected]>
Co-authored-by: Matthew Soulanille <[email protected]>
dydavidkim added a commit to CodeSmithDSMLProjects/tfjs that referenced this pull request Sep 28, 2022
* Customize setTimeout (tensorflow#6694)

If the setTimeout nesting level is greater than 5 and timeout is less
than 4ms, timeout will be clamped to 4ms, which hurts the perf. A custom
setTimeout is provided to mitigate the perf impact.

BUG: tensorflow#6687
Co-authored-by: Na Li <[email protected]>

* Upgrade windows BrowserStack chrome to 104 (tensorflow#6866)

* webgpu: Disable importExternalTexture (tensorflow#6868)

WebGPU Working Group recently found some problem with
importExtenalTexture in spec, so we have to disable it temporarily.

Co-authored-by: Yang Gu <[email protected]>
Co-authored-by: Na Li <[email protected]>
Co-authored-by: Matthew Soulanille <[email protected]>
dydavidkim added a commit to CodeSmithDSMLProjects/tfjs that referenced this pull request Sep 29, 2022
* Customize setTimeout (tensorflow#6694)

If the setTimeout nesting level is greater than 5 and timeout is less
than 4ms, timeout will be clamped to 4ms, which hurts the perf. A custom
setTimeout is provided to mitigate the perf impact.

BUG: tensorflow#6687
Co-authored-by: Na Li <[email protected]>

* Upgrade windows BrowserStack chrome to 104 (tensorflow#6866)

* webgpu: Disable importExternalTexture (tensorflow#6868)

WebGPU Working Group recently found some problem with
importExtenalTexture in spec, so we have to disable it temporarily.

* Refactored Resizing Layer Unit Tests (#38)

* Rescaling Preprocessing Layer
Co-authored-by:
David Kim (@koyykdy) <[email protected]>
Brian Zheng (@Brianzheng123) <[email protected]>

* PR issues resolved

* linting and PR issues resolved
Co-authored-by: Adam Lang (@AdamLang96) <[email protected]>
Co-authored-by: (@Brianzheng123) <[email protected]>

* initial implementation of image preprocessing: resizing layer, and associated unit tests. Comments and refactoring for image scaling layer

* refactoring in computeOutputShape for image resizing layer

* Unit tests for image resizing preprocessing layer expanded and refactored

* refactored unit tests for resizing layer

* Preprocessing-Resizing layer unit test expansion and refactoring.
Co-authored-by: Adam Lang <@AdamLang96> ([email protected])

* cleaning up commit diffs

* cleaning up commit diffs

* PR commit suggestions accepted - code refactored to reflect changes

* resizing layer unit test refactoring

Co-authored-by: AdamLang96 <[email protected]>

* Linting issue resolved: unused import statement culled (#39)

* Rescaling Preprocessing Layer
Co-authored-by:
David Kim (@koyykdy) <[email protected]>
Brian Zheng (@Brianzheng123) <[email protected]>

* PR issues resolved

* linting and PR issues resolved
Co-authored-by: Adam Lang (@AdamLang96) <[email protected]>
Co-authored-by: (@Brianzheng123) <[email protected]>

* initial implementation of image preprocessing: resizing layer, and associated unit tests. Comments and refactoring for image scaling layer

* refactoring in computeOutputShape for image resizing layer

* Unit tests for image resizing preprocessing layer expanded and refactored

* refactored unit tests for resizing layer

* Preprocessing-Resizing layer unit test expansion and refactoring.
Co-authored-by: Adam Lang <@AdamLang96> ([email protected])

* cleaning up commit diffs

* cleaning up commit diffs

* PR commit suggestions accepted - code refactored to reflect changes

* resizing layer unit test refactoring

* linting issues resolved: unusued import statement culled

Co-authored-by: AdamLang96 <[email protected]>

* Update jasmine_util.ts (tensorflow#6872)

FIX

* webgl: Fix NaN issue (tensorflow#6828)

Fix tensorflow#6822

Problem
1: On some GPUs, even if a and b are both non-NaN, the value of isNaN in vec4 isNaN = min(vec4(isnan(a)) + vec4(isnan(b)), vec4(1.0)); are still larger than 0., which misleads all values become NAN.
2: After resolving NAN issue, the result is still incorrect. It seems that the isnan_custom is not well supported on the problem GPU. After switching back to builtin isnan, everything works well.

Solution:
Use the bool type bvec4 instead of float type vec4 to calculate isNaN to avoid the the float precision issue when comparing with zero.
Meanwhile, add an env flag WEBGL2_ISNAN_CUSTOM to allow user to specify which isnan to use.

* Upgrade nodejs to 18.7.0 (tensorflow#6863)

* Upgrade nodejs to 18.7.0

* Fix hash table test string not passed as base64

* fixed prelu fusing code that pre-maturely neg the const on multiply (tensorflow#6876)

Co-authored-by: RajeshT <[email protected]>

* Update tfjs-layers/src/layers/preprocessing/image_resizing.ts

Co-authored-by: Matthew Soulanille <[email protected]>

Co-authored-by: Yang Gu <[email protected]>
Co-authored-by: Na Li <[email protected]>
Co-authored-by: Matthew Soulanille <[email protected]>
Co-authored-by: AdamLang96 <[email protected]>
Co-authored-by: Linchenn <[email protected]>
Co-authored-by: Jiajia Qin <[email protected]>
Co-authored-by: Ping Yu <[email protected]>
Co-authored-by: RajeshT <[email protected]>
Co-authored-by: Matthew Soulanille <[email protected]>

Co-authored-by: Yang Gu <[email protected]>
Co-authored-by: Na Li <[email protected]>
Co-authored-by: Matthew Soulanille <[email protected]>
Co-authored-by: AdamLang96 <[email protected]>
Co-authored-by: Linchenn <[email protected]>
Co-authored-by: Jiajia Qin <[email protected]>
Co-authored-by: Ping Yu <[email protected]>
Co-authored-by: RajeshT <[email protected]>
Co-authored-by: Matthew Soulanille <[email protected]>
// Skip the first few samples because the browser does not clamp the timeout
const skipCount = 5;

it('setTimeout', (done) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gyagp I began to see this test fail on Linux, maybe related with https://chromestatus.com/feature/5710690097561600

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hujiajie What's your channel and version of Chrome? I tried both Stable (108.0.5359.124) and Dev (110.0.5478.4) on Linux, but the nesting levels are still 5. I also double checked Windows, with Stable (108.0.5359.125) and Canary (111.0.5491.0), and the nesting levels are also 5.
My testing program is timer.html at https://github.com/webatintel/webatintel.github.io. You need to download it to local (otherwise the result is impacted by the network condition) and type "/timer.html?test=setTimeout&maxCount=30" in the address bar.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, it seems chromestatus is lying here, and the feature is still in field trial. What if you add --enable-features=MaxUnthrottledTimeoutNestingLevel?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this option, nesting level is 15. I will do the change once Chrome really enables this in the stable channel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants