mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-04-29 03:00:14 -04:00
* WebGL WIP * 84% of ops passing test * tests passing 100% * Cleanup, refactor * Shave off some lines * Work on dtypes * TestOps at 100% again * Efficient net shaders compile in browser webgl2 * Compile all efficientnet shaders in browser * Create empty textures for tensor buffers * Run program. Up next weight loading * Exported WebGL model working * Add tests, refactor * Explicit cast alu for GLSL * Fix CI tests * WebGL efficientnet demo * Compile and run yolov8 in browser * Fix imports * Simplify yolo compile * Fix bool*bool and cast cmplt to float * More tests * Do std tests pass on CI? * Skip std tests on CI * Remove explicit_cast_alu hack, and solve it in code_for_op * Move to new dtype-less alloc api * Remove local size hack: optimize local_size only if device has local * Remove glsl.py, and move content to cstyle * dont_use_locals in opts * Fix dtype tests * type_map in CStyleLanguage * Make core changes smaller, cleaner, refactor export_model and demo * Skip pad_slice * Simplify: render_const, render_conditional * solve bool alu for other binops, cleaner ops_webgl * Fix noopt hack * Remove some skipIfs * WebGL image hack * type_names is a better name * global_max * Fix dtype import * Fix type_names -> type_map * Fix lint * Remove webgpu, back to 5k lines (#3040) * remove webgpu * max 5000 lines * revert those to master * retain that cstyle --------- Co-authored-by: Ahmed Harmouche <ahmedharmouche92@gmail.com>
24 lines
1.1 KiB
Python
24 lines
1.1 KiB
Python
from pathlib import Path
|
|
from examples.yolov8 import YOLOv8
|
|
from tinygrad.tensor import Tensor
|
|
from tinygrad.nn.state import safe_save
|
|
from extra.export_model import export_model
|
|
from tinygrad.helpers import fetch
|
|
from tinygrad.helpers import getenv
|
|
from tinygrad.device import Device
|
|
from tinygrad.nn.state import safe_load, load_state_dict
|
|
|
|
if __name__ == "__main__":
|
|
Device.DEFAULT = "WEBGL"
|
|
yolo_variant = 'n'
|
|
yolo_infer = YOLOv8(w=0.25, r=2.0, d=0.33, num_classes=80)
|
|
weights_location = Path(__file__).parents[1] / "weights" / f'yolov8{yolo_variant}.safetensors'
|
|
fetch(f'https://gitlab.com/r3sist/yolov8_weights/-/raw/master/yolov8{yolo_variant}.safetensors', weights_location)
|
|
state_dict = safe_load(weights_location)
|
|
load_state_dict(yolo_infer, state_dict)
|
|
prg, inp_sizes, out_sizes, state = export_model(yolo_infer, Device.DEFAULT.lower(), Tensor.randn(1,3,640,640))
|
|
dirname = Path(__file__).parent
|
|
safe_save(state, (dirname / "net.safetensors").as_posix())
|
|
with open(dirname / f"net.js", "w") as text_file:
|
|
text_file.write(prg)
|