Author Topic: Conscious Artificial Intelligence - Project Update  (Read 94130 times)

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #210 on: September 17, 2026, 10:31:11 pm »
:) @hshatti, :)
THIS IS SO COOOOLLLL!!!!. And the best part, you tested on AMD with a 27B parameters model!!!!

The prefil numbers on your testing look very bad. When I test with 7K tokens for input, the prefil is many times faster than generation.

Anyway, in the case that you like, you could use these settings for larger inputs:
Code: Pascal  [Select][+][-]
  1. --prefill-window 64 --prefill-tail-window 8

Also, if you are using ChatServer, you can also try:
Code: Pascal  [Select][+][-]
  1. --cache-checkpoints 16

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #211 on: September 18, 2026, 12:17:17 pm »
:) @hshatti, :)
On your 4B model, can I suggest please to run the same int4 test on CPU (--cpu) ? It will be super cool to find how your AMD CPU does.

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #212 on: September 24, 2026, 09:04:15 pm »
:) Just to comment that the coding to support Qwen Image 2.1 has started. :)
https://github.com/QwenLM/Qwen-Image-2.1

hshatti

  • New Member
  • *
  • Posts: 24
  • Be kind!
Re: Conscious Artificial Intelligence - Project Update
« Reply #213 on: September 30, 2026, 10:14:50 pm »
Hi, @schuler

Sorry for not coming back earlier here are some of the results after the most recent git pull but this time using my other GPU Intel Arc Pro B50, this is a nice little nifty yet capable GPU that I use for low power inferencing.

Qwen 3.5 4B  with --int4 (Q4_0) re-quantization OpenCL - Intel Arc Pro B50 Release mode:
Code: [Select]
Code: [Select]
Model loaded : 10.8s.
GPU offload  :  6.7s.
Time to fill : 422 ms
Prefill      : 40.9 tok/s
Token Gen    : 50.8 tok/s

Prefill and TTF here seems normal!, i used the provided parameters, and got a similar figures, I'm still puzzled why my AMD GPU was slower despite the better X2 performance and memory, OpenCL driver issues perhaps? I'll try to find time to dig into debugging it, I'll share with you my findings once I'm able to spot it


Qwen 3.8 27B  with --int4 (Q4_0) re-quantization OpenCL - Intel Arc Pro B50 Release mode:
Code: [Select]
Code: [Select]
Model loaded : 60.4s.
GPU offload  : 42.2s.
Time to fill : 22344 ms
Prefill      : 0.9 tok/s
Token Gen    : 6.2 tok/s

Well... as a dense model, Qwen 3.8 27B size was really massive so it couldn't totally fit in the 16GB internal vram here and had to borrow ~2.7GB from the shared GPU memory which explains the significant performance hit! for int4 quantisation I was anticipating around 14GB GPU offload, maybe because of mixed precisions. any parameters to squeeze it further?

Quote
On your 4B model, can I suggest please to run the same int4 test on CPU (--cpu) ? It will be super cool to find how your AMD CPU does.
here you go:
Qwen 3.5 4B  with --int4 (Q4_0) re-quantization OpenCL - AMD Ryzen 9 9900X 24T 12C - 32GB DDR5 CL30 clocked to 4800MT/s Release mode:
Code: [Select]
Code: [Select]
Model loaded : 10.9s.
GPU offload  : N/A
Time to fill : 921 ms
Prefill      : 18.6 tok/s
Token Gen    : 16.1 tok/s
Impressive!!... here is one little issue, my CPU supports AVX512 and all of it's extensions, I compiled CAI with FPC 3.2.2 which doesn't support AVX512, I tried FPC 3.3.1 (recent trunk release, clean and build..) but got lot's of compiling errors.

Quote
:) Just to comment that the coding to support Qwen Image 2.1 has started. :)
Wow .. great minds think alike!!! ;)

I also have an NVIDIA DGX Spark but it for some reason it hates OpenCL!!, yet I really wish to test CAI on it, would you be interested in integrating CUDA with it? and if so, I'm happy to contribute do you take PRs in this regards?

I'm working on Vulkan implementation for Envision still rough on the edges, (GEMM further optimisation phase) I think i can also help there if this is on your radar.
« Last Edit: September 30, 2026, 10:56:49 pm by hshatti »
Comrades!, Unpython the world

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #214 on: October 01, 2026, 02:58:39 am »
Does CAI Neural support building a proper Temporal Convolutional Network (TCN) for multivariate time-series classification/prediction?

In particular, I’m interested in a network with:

causal 1D convolutions,
increasing dilations such as 1, 2, 4, 8, 16,
residual connections,
multiple input features/channels per time step,
fixed rolling input windows,
and an output classification/probability layer.

I noticed TNNetCausalConv1D and wondered whether this, together with the existing residual/sum layers, is sufficient to implement a standard TCN architecture, or whether CAI Neural already has a recommended TCN implementation/example.

Also, does training/backpropagation fully support dilation in TNNetCausalConv1D, and is this architecture reasonably optimized for CPU training with AVX/AVX2?

If you have an example of a small TCN built with CAI Neural, I’d be very interested in seeing the recommended layer structure.

@fpcoder,
I will copy here  a definition from Gemini regarding what a Temporal Convolutional Network (TCN) is:
Quote
A Temporal Convolutional Network (TCN) is a specialized deep learning architecture adapted from 1D convolutional neural networks designed to model and forecast sequential or time-series data. 
Core Architectural Principles
  • Causal Convolutions: The model uses convolutions where an output at time t is derived only from elements at time t and previous times in the earlier layer. This strictly prevents future data leakage.
  • Dilated Convolutions: Convolutions skip input values by a step size (dilation factor d) that grows exponentially (e.g., \(1, 2, 4, \dots\)) as layers deepen. This expands the network's receptive field to capture long-range dependencies without excessive computational cost.
  • Residual Connections: Blocks include skip connections that ease gradient flow, preventing the vanishing gradient problem common in deep sequential networks.
Advantages over RNNs and LSTMs
  • Parallel Processing: Unlike Recurrent Neural Networks (RNNs) or LSTMs that process steps sequentially (hindering parallelization), TCN convolutions process all time steps in parallel during training. 
  • Stable Gradients: They avoid exponential blowups or decays in gradients over long sequences by maintaining a fixed-length history and stable backpropagation paths.
  • Flexible Receptive Field: You can easily tune the window of history the model looks at by changing the kernel size, dilation factors, and number of residual blocks.
Common Applications
  • Time-Series Forecasting: Predicting future stock prices, energy loads, or weather trends.
  • Speech and Audio Processing: Speech enhancement and dereverberation.
  • Action Recognition & Tracking: Segmenting human activities or autonomous vehicle trajectory prediction. 

I then asked Claude Opus 5.5 to code an example for you (I have not tested):
Code: Pascal  [Select][+][-]
  1. function AddTCNBlock(NN: TNNet; Channels, K, Dilation: integer;
  2.      DropRate: TNeuralFloat): TNNetLayer;
  3.    var Skip: TNNetLayer;
  4.    begin
  5.      Skip := NN.GetLastLayer;
  6.      NN.AddLayer(TNNetCausalConv1D.Create(Channels, K, 0, Dilation));
  7.      NN.AddLayer(TNNetReLU.Create());
  8.      NN.AddLayer(TNNetSpatialDropout1D.Create(DropRate));
  9.      NN.AddLayer(TNNetCausalConv1D.Create(Channels, K, 0, Dilation));
  10.      NN.AddLayer(TNNetReLU.Create());
  11.      NN.AddLayer(TNNetSpatialDropout1D.Create(DropRate));
  12.      // 1x1 projection on the skip path when the channel count changes
  13.      if Skip.Output.Depth <> Channels then
  14.        Skip := NN.AddLayerAfter(TNNetPointwiseConvLinear.Create(Channels), Skip);
  15.      NN.AddLayer(TNNetSum.Create([NN.GetLastLayer, Skip]));
  16.      Result := NN.AddLayer(TNNetReLU.Create());
  17.    end;
Code: Pascal  [Select][+][-]
  1.    NN := TNNet.Create();
  2.    NN.AddLayer(TNNetInput.Create(WindowLen, 1, NumFeatures));
  3.    for Dil in [1, 2, 4, 8, 16] do AddTCNBlock(NN, 32, 3, Dil, 0.1);
  4.    NN.AddLayer(TNNetCrop.Create(WindowLen - 1, 0, 1, 1)); // last time step
  5.    NN.AddLayer(TNNetFullConnectLinear.Create(NumClasses));
  6.    NN.AddLayer(TNNetSoftMax.Create());

Yes. Backpropagation is supported. AVX/AVX2 should take place.

I am adding to the tasklist file a task to add a proper example.

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #215 on: October 01, 2026, 03:13:57 am »
@hshatti,
Thank you so much!

Impressive!!... here is one little issue, my CPU supports AVX512 and all of it's extensions, I compiled CAI with FPC 3.2.2 which doesn't support AVX512

Try this:
Code: Pascal  [Select][+][-]
  1. lazbuild ... --opt="-dAVX512"
If you search for "AVX512", you will find the trick. Regarding the new FPC, I have fixes to submit to the FPC compiler project that fix compilation with CAI for ages. I will submit these fixes eventually.

Quote
I'm still puzzled why my AMD GPU was slower despite the better X2 performance and memory
Speculation: memory throughput and/or caching mechanism.

hshatti

  • New Member
  • *
  • Posts: 24
  • Be kind!
Re: Conscious Artificial Intelligence - Project Update
« Reply #216 on: October 01, 2026, 03:08:13 pm »
Hi @schuler,

Quote
Try this:
Code: Pascal  [Select][+][-]
  1. lazbuild ... --opt="-dAVX512"

If you search for "AVX512", you will find the trick. Regarding the new FPC, I have fixes to submit to the FPC compiler project that fix compilation with CAI for ages. I will submit these fixes eventually.
Previously I did include -dAVX512 switch so this is the same as running from lazarus and got the same errors with lazbuild. but I found the problem! here are the issues and my improvised workaround :

pascoremath32
 -  inlining the unit interface functions is likely troubling FPC 3.3.1 optimiser while converting higher precision constant floats (Double) to lower precision (single) resulting an arithmetic overflow error at compile time, so I rewrapped each inline keyword:
 
Code: Pascal  [Select][+][-]
  1. {$IFDEF FPC} inline; {$ENDIF}
with
Code: Pascal  [Select][+][-]
  1. {$IF DEFINED(FPC) AND not DEFINED(VER3_3)} inline; {$ENDIF}
and voila! my assumption this will allow the optimiser (>O2) to conveniently choose whether to inline or not.

testing the same Qwen 35 4B model with AVX512 though didn't make any significant difference except the only model loading time was reduced from 10.9s to 6.7s.

Cheers  8)
« Last Edit: October 01, 2026, 03:10:07 pm by hshatti »
Comrades!, Unpython the world

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #217 on: October 01, 2026, 05:44:25 pm »
Does CAI Neural support building a proper Temporal Convolutional Network (TCN) for multivariate time-series classification/prediction?
...
If you have an example of a small TCN built with CAI Neural, I’d be very interested in seeing the recommended layer structure.

Claude Opus 5.5 coded and tested an example not yet merged into master:
https://github.com/joaopauloschuler/neural-api/tree/a19/examples/TCNClassifier

fpcoder

  • Hero Member
  • *****
  • Posts: 673
  • Previously kapibara
Re: Conscious Artificial Intelligence - Project Update
« Reply #218 on: October 02, 2026, 12:41:53 am »

Claude Opus 5.5 coded and tested an example not yet merged into master:
https://github.com/joaopauloschuler/neural-api/tree/a19/examples/TCNClassifier

Great, I will experiment with that.
Lazarus trunk / fpc 3.3.1 / Kubuntu 24.04 - 64 bit

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #219 on: October 02, 2026, 01:57:25 am »
Hi @schuler,

pascoremath32
 -  inlining the unit interface functions is likely troubling FPC 3.3.1 optimiser while converting higher precision constant floats (Double) to lower precision (single) resulting an arithmetic overflow error at compile time, so I rewrapped each inline keyword:
 
Code: Pascal  [Select][+][-]
  1. {$IFDEF FPC} inline; {$ENDIF}
with
Code: Pascal  [Select][+][-]
  1. {$IF DEFINED(FPC) AND not DEFINED(VER3_3)} inline; {$ENDIF}
and voila! my assumption this will allow the optimiser (>O2) to conveniently choose whether to inline or not.

testing the same Qwen 35 4B model with AVX512 though didn't make any significant difference except the only model loading time was reduced from 10.9s to 6.7s.

Cheers  8)

Interesting finding! Thank you!

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #220 on: October 02, 2026, 05:43:57 pm »
maybe because of mixed precisions. any parameters to squeeze it further?

I've just updated the master branch. I expect 10% faster inference on NVIDIA video cards (I have not tested the updated master on other cards). Besides, my own experiments are run with:
Code: Pascal  [Select][+][-]
  1. --stats --profile --gpu --int4 --max-fast-memory --prefill-window 64 --prefill-tail-window 8

For the ChatServer, I also include:
Code: Pascal  [Select][+][-]
  1. --cache-checkpoints 16 --port 5000
« Last Edit: October 02, 2026, 05:46:25 pm by schuler »

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #221 on: October 09, 2026, 07:35:43 pm »

fcu

  • Full Member
  • ***
  • Posts: 136
Re: Conscious Artificial Intelligence - Project Update
« Reply #222 on: October 09, 2026, 09:36:08 pm »
man , this is huge and very impressive , i will jump into it even i have a little knowledge about AI 

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #223 on: October 15, 2026, 01:29:23 am »
How to add an LLM to your project:
Code: Pascal  [Select][+][-]
  1. //git clone https://huggingface.co/Qwen/Qwen2.5-0.5B-Instruct q
  2. program SimpleChat;
  3. {$mode objfpc}{$H+}
  4. uses
  5.   {$IFDEF UNIX} cthreads, {$ENDIF}
  6.   neuralchat, neuralchatengine;
  7.  
  8. var
  9.   Options: TChatOptions;
  10.   Engine: TChatEngine;
  11.   ErrorMsg: string;
  12.   History: TChatMessages;
  13. begin
  14.   Options := DefaultChatOptions();          // int8 weights, model's sampling defaults
  15.   Options.ModelDir := 'q';                  // git clone of Qwen/Qwen2.5-0.5B-Instruct
  16.   Options.CtxLen := 2048;                   // keeps the KV cache small
  17.   Engine := TChatEngine.Create();
  18.   try
  19.     if Engine.LoadModel(Options, ErrorMsg) then
  20.     begin
  21.       History := [ChatMessage('user', 'Name three colours.')];
  22.       WriteLn(Engine.ChatReply(History, Engine.Opt));
  23.     end
  24.     else
  25.       WriteLn('Error: ', ErrorMsg);
  26.   finally
  27.     Engine.Free;
  28.   end;
  29. end.
See:
* https://www.youtube.com/shorts/0nPiu-M_YoQ
* https://github.com/joaopauloschuler/neural-api/tree/master/examples/ChatTerminal
« Last Edit: October 15, 2026, 02:05:20 am by schuler »

schuler

  • Sr. Member
  • ****
  • Posts: 404
Re: Conscious Artificial Intelligence - Project Update
« Reply #224 on: October 18, 2026, 06:16:34 pm »
 :) You can now embed Text-To-Speach (TTS) into your own FPC code  :)
Code: Pascal  [Select][+][-]
  1. program SimpleKokoroTTS;
  2. {$mode objfpc}{$H+}
  3. uses
  4.   {$IFDEF UNIX} cthreads, {$ENDIF}
  5.   neuralkokorosession;
  6.  
  7. var
  8.   Options: TKokoroSessionOptions;
  9.   Session: TKokoroSession;
  10. begin
  11.   Options := DefaultKokoroSessionOptions();      // voice af_heart, speed 1, CPU
  12.   Options.ModelDir := 'k';                        // git clone of hexgrad/Kokoro-82M
  13.   Options.DictionaryDir := 'misaki/misaki/data';  // git clone of hexgrad/misaki
  14.   Session := TKokoroSession.Create(Options);      // loads the model and voice once
  15.   try
  16.     Session.SpeakTextToWav(                       // a long text works too
  17.       'A small red fox lived at the edge of a quiet forest. ' +
  18.       'Every morning she ran down to the river to drink. ' +
  19.       'One cold winter day she counted 3 rabbits in the snow. ' +
  20.       'They looked at her, and she looked at them. ' +
  21.       'Then the fox turned around and went home to sleep.', 'story.wav');
  22.   finally
  23.     Session.Free;
  24.   end;
  25. end.

I attached the result transformed into mp3 with:
Code: Pascal  [Select][+][-]
  1. !ffmpeg -i /content/story.wav -codec:a libmp3lame -qscale:a 2 /content/story.mp3

No GPU is required.

More details at: https://github.com/joaopauloschuler/neural-api/tree/master/examples/KokoroTTS

 

TinyPortal © 2005-2018