@@ -28,7 +28,7 @@ class ModuleTest: XCTestCase {
2828 if let path = resourceBundle. path ( forResource: name, ofType: type) {
2929 return path
3030 }
31- let message = " \( name) . \( type) not bundled — run extension/apple/ExecuTorch/__tests__/resources/generate_coreml_test_models.py to generate it . "
31+ let message = " \( name) . \( type) not bundled. "
3232 if ProcessInfo . processInfo. environment [ " CI " ] != nil {
3333 // Throw a plain Error (NOT XCTSkip) so the test is reported as failed
3434 // rather than skipped. The thrown error's localizedDescription is the
@@ -263,80 +263,10 @@ class ModuleTest: XCTestCase {
263263 XCTAssertFalse ( desc. contains ( " 0x " ) , " description should not include a pointer: \( desc) " )
264264 }
265265
266- func testLoadWithBackendOptions( ) throws {
267- guard let modelPath = resourceBundle. path ( forResource: " add " , ofType: " pte " ) else {
268- XCTFail ( " Couldn't find the model file " )
269- return
270- }
271- let module = Module ( filePath: modelPath)
272- let options = try BackendOptionsMap ( options: [
273- " SomeBackend " : [
274- BackendOption ( " num_threads " , 4 ) ,
275- BackendOption ( " use_cache " , true ) ,
276- ]
277- ] )
278- XCTAssertNoThrow ( try module. load ( options) )
279- XCTAssertTrue ( module. isLoaded ( ) )
280- }
281-
282- func testLoadWithEmptyBackendOptions( ) throws {
283- guard let modelPath = resourceBundle. path ( forResource: " add " , ofType: " pte " ) else {
284- XCTFail ( " Couldn't find the model file " )
285- return
286- }
287- let module = Module ( filePath: modelPath)
288- let options = try BackendOptionsMap ( options: [ : ] )
289- XCTAssertNoThrow ( try module. load ( options) )
290- XCTAssertTrue ( module. isLoaded ( ) )
291- }
292-
293- func testLoadMethodWithBackendOptions( ) throws {
294- guard let modelPath = resourceBundle. path ( forResource: " add " , ofType: " pte " ) else {
295- XCTFail ( " Couldn't find the model file " )
296- return
297- }
298- let module = Module ( filePath: modelPath)
299- let options = try BackendOptionsMap ( options: [
300- " SomeBackend " : [
301- BackendOption ( " compute_unit " , " cpu_and_gpu " ) ,
302- ]
303- ] )
304- XCTAssertNoThrow ( try module. load ( " forward " , options: options) )
305- XCTAssertTrue ( module. isLoaded ( " forward " ) )
306- }
307-
308- func testLoadWithBackendOptionsThenExecute( ) throws {
309- guard let modelPath = resourceBundle. path ( forResource: " add " , ofType: " pte " ) else {
310- XCTFail ( " Couldn't find the model file " )
311- return
312- }
313- let module = Module ( filePath: modelPath)
314- let options = try BackendOptionsMap ( options: [
315- " SomeBackend " : [
316- BackendOption ( " num_threads " , 4 ) ,
317- ]
318- ] )
319- XCTAssertNoThrow ( try module. load ( options) )
320-
321- let inputs : [ Tensor < Float > ] = [ Tensor ( [ 1 ] ) , Tensor ( [ 1 ] ) ]
322- var outputs : [ Value ] ?
323- XCTAssertNoThrow ( outputs = try module. forward ( inputs) )
324- XCTAssertEqual ( outputs? . first? . tensor ( ) , Tensor ( [ Float ( 2 ) ] ) )
325- }
326-
327- // Regression test: when load(_:BackendOptionsMap) is followed by a lazy
328- // load_method (triggered by forward without an explicit load("forward")),
329- // the C++ LoadBackendOptionsMap held inside the BackendOptionsMap must
330- // outlive the wrapper call. The Module retains the BackendOptionsMap via
331- // ARC for exactly that reason. The per-delegate loop in Method::init
332- // would otherwise dereference a dangling pointer in strcmp and crash
333- // with EXC_BAD_ACCESS.
334- //
335- // The plain add.pte fixture does NOT trigger this because it has zero
336- // delegates, so the per-delegate loop never executes. We use a
337- // CoreML-delegated add model (add_coreml.pte, generated at CI time by
338- // resources/generate_coreml_test_models.py) which has at least one
339- // delegate.
266+ // Regression test for the lazy load_method path: after load(options),
267+ // forward() triggers load_method which must still see valid backend
268+ // options. Requires a delegated model — the plain add.pte has no
269+ // delegates and so does not exercise the code path.
340270 func testLoadWithBackendOptionsThenExecuteOnCoreMLDelegatedModel( ) throws {
341271 let modelPath = try requireFixture ( " add_coreml " , ofType: " pte " )
342272 let module = Module ( filePath: modelPath)
0 commit comments