ipex-llm
ipex-llm copied to clipboard
Chronos: Lazy load Forecaster
Description
Modules are not loaded immediately, but are delayed until runtime.
1. Why the change?
It takes about 3s to initialize Forecaster, but only 1.5S after using lazyimport
.
2. User API changes
No changed
3. Summary of the change
Optimized forecaster startup time, Runs 100% faster.
4. How to test?
- [ ] Unit test
- [ ] Application test
5. API usage
# 1. Import module from name
np = LazyImport('numpy')
np.ndarray # Lazyimport will call __getattr__
np.array([[1,2,3],[4,5,6]]) # np will call __getattr__ twice without calling __call__.
# 2. Import module from function
array = LazyImport('numpy.array')
array([[1,2,3],[4,5,6]]) # array will call `__call__` method.
In __init__.py, only use the second method.
6. Known issues
- [x] LazyImport imports may import multiple times
- [x] LazyImport does not throw errors and warnings
- [x] LazyImport may import all Forecasters, making the message unfriendly.
- [ ] other possible changes: remove some xxx_available, Because the loading process is deferred until after the call or getattribute
- [x] The form bigdl.chronos.forecaster.lstm_forecaster.LSTMForecaster is not accepted because LSTMForecaster is a class
- [ ] Migration Comments
Can we delete some xxx_available
because their functions have been replaced. @TheaperDeng
http://10.112.231.51:18889/view/BigDL-PR-Validation/job/BigDL-Chronos-PR-Validation/693/